Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/SegmentedButtons/SegmentedButtonItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -122,6 +127,7 @@ const SegmentedButtonItem = ({
style,
labelStyle,
showSelectedCheck,
checkedIcon = 'check',
checkedColor,
uncheckedColor,
background,
Expand Down Expand Up @@ -234,7 +240,7 @@ const SegmentedButtonItem = ({
>
{showCheckedIcon ? (
<Animated.View style={[iconStyle, checkAnimatedStyle]}>
<Icon source={'check'} size={iconSize} color={textColor} />
<Icon source={checkedIcon} size={iconSize} color={textColor} />
</Animated.View>
) : null}
{showIcon && icon ? (
Expand Down
2 changes: 2 additions & 0 deletions src/components/SegmentedButtons/SegmentedButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type Props<T extends string = string> = {
* - `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
*/
Expand All @@ -68,6 +69,7 @@ export type Props<T extends string = string> = {
onPress?: (event: GestureResponderEvent) => void;
label?: string;
showSelectedCheck?: boolean;
checkedIcon?: IconSource;
style?: StyleProp<ViewStyle>;
labelStyle?: StyleProp<TextStyle>;
testID?: string;
Expand Down
26 changes: 26 additions & 0 deletions src/components/__tests__/SegmentedButton.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(
<PaperProvider settings={{ icon }}>
<SegmentedButtons
value="walk"
onValueChange={() => {}}
buttons={[
{
value: 'walk',
label: 'Walking',
showSelectedCheck: true,
checkedIcon: 'star',
},
]}
/>
</PaperProvider>
);

expect(icon).toHaveBeenCalledWith(
expect.objectContaining({ name: 'star' })
);
});
});

describe('should have `accessibilityState={ checked: true }` when selected', () => {
Expand Down
Loading