diff --git a/src/components/SegmentedButtons/SegmentedButtonItem.tsx b/src/components/SegmentedButtons/SegmentedButtonItem.tsx index c0df4c8b7a..60dbd3249f 100644 --- a/src/components/SegmentedButtons/SegmentedButtonItem.tsx +++ b/src/components/SegmentedButtons/SegmentedButtonItem.tsx @@ -88,6 +88,11 @@ export type Props = { * Show optional check icon to indicate selected state */ showSelectedCheck?: boolean; + /** + * Icon shown with `showSelectedCheck` while this button is checked. + * Defaults to `check`. + */ + checkedIcon?: IconSource; /** * Density is applied to the height, to allow usage in denser UIs. */ @@ -122,6 +127,7 @@ const SegmentedButtonItem = ({ style, labelStyle, showSelectedCheck, + checkedIcon = 'check', checkedColor, uncheckedColor, background, @@ -234,7 +240,7 @@ const SegmentedButtonItem = ({ > {showCheckedIcon ? ( - + ) : null} {showIcon && icon ? ( diff --git a/src/components/SegmentedButtons/SegmentedButtons.tsx b/src/components/SegmentedButtons/SegmentedButtons.tsx index 486c8f1009..4194b4690e 100644 --- a/src/components/SegmentedButtons/SegmentedButtons.tsx +++ b/src/components/SegmentedButtons/SegmentedButtons.tsx @@ -55,6 +55,7 @@ export type Props = { * - `onPress`: callback that is called when button is pressed * - `label`: label text of the button * - `showSelectedCheck`: show optional check icon to indicate selected state + * - `checkedIcon`: icon shown with `showSelectedCheck` while the button is checked. Defaults to `check` * - `style`: pass additional styles for the button * - `testID`: testID to be used on tests */ @@ -68,6 +69,7 @@ export type Props = { onPress?: (event: GestureResponderEvent) => void; label?: string; showSelectedCheck?: boolean; + checkedIcon?: IconSource; style?: StyleProp; labelStyle?: StyleProp; testID?: string; diff --git a/src/components/__tests__/SegmentedButton.test.tsx b/src/components/__tests__/SegmentedButton.test.tsx index 807d5eb502..06ebca299f 100644 --- a/src/components/__tests__/SegmentedButton.test.tsx +++ b/src/components/__tests__/SegmentedButton.test.tsx @@ -1,5 +1,6 @@ import { describe, expect, it, jest } from '@jest/globals'; +import PaperProvider from '../../core/PaperProvider'; import { render, screen } from '../../test-utils'; import { LightTheme } from '../../theme/schemes'; import { tokens } from '../../theme/tokens'; @@ -404,6 +405,31 @@ describe('should not render icon when', () => { expect(tree).toMatchSnapshot(); }); + + it('uses checkedIcon for the selected check', async () => { + const icon = jest.fn(() => null); + + await render( + + {}} + buttons={[ + { + value: 'walk', + label: 'Walking', + showSelectedCheck: true, + checkedIcon: 'star', + }, + ]} + /> + + ); + + expect(icon).toHaveBeenCalledWith( + expect.objectContaining({ name: 'star' }) + ); + }); }); describe('should have `accessibilityState={ checked: true }` when selected', () => {