From 684ea23df09186950935b01cd2b63db9a58c6908 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 24 Nov 2026 18:52:02 -0400 Subject: [PATCH] fix(segmented-buttons): use a custom icon for the selected check showSelectedCheck always drew the check glyph. A button can now pass checkedIcon, which still defaults to check. Fixes #4296 --- .../SegmentedButtons/SegmentedButtonItem.tsx | 8 +++++- .../SegmentedButtons/SegmentedButtons.tsx | 2 ++ .../__tests__/SegmentedButton.test.tsx | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) 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', () => {