From cbec66fc40a78970715fff2d6bef8724b3034efa Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Thu, 28 Sep 2023 09:27:42 -0700 Subject: [PATCH] Add testIDs prop to SegmentedControl --- .../components/SegmentedControl/SegmentedControl.stories.tsx | 1 + .../src/components/SegmentedControl/SegmentedControl.tsx | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/packages/components/src/components/SegmentedControl/SegmentedControl.stories.tsx b/packages/components/src/components/SegmentedControl/SegmentedControl.stories.tsx index eac22413..8c764316 100644 --- a/packages/components/src/components/SegmentedControl/SegmentedControl.stories.tsx +++ b/packages/components/src/components/SegmentedControl/SegmentedControl.stories.tsx @@ -52,6 +52,7 @@ export const twoSegments: Story = { 'You have 3 unread messages. Review messages in your inbox', 'Review your folders', ], + testIDs: ['test-id-1', 'test-id-2'], }, parameters: { design: [ diff --git a/packages/components/src/components/SegmentedControl/SegmentedControl.tsx b/packages/components/src/components/SegmentedControl/SegmentedControl.tsx index 5e5a8855..31aaa108 100644 --- a/packages/components/src/components/SegmentedControl/SegmentedControl.tsx +++ b/packages/components/src/components/SegmentedControl/SegmentedControl.tsx @@ -27,6 +27,8 @@ export type SegmentedControlProps = { a11yLabels?: string[] /** Optional array of segment accessibility hints */ a11yHints?: string[] + /** Optional array of test IDs for test suites */ + testIDs?: string[] } type SegmentProps = { @@ -52,6 +54,7 @@ export const SegmentedControl: FC = ({ selected, a11yLabels, a11yHints, + testIDs, }) => { const { t } = useTranslation() const colorScheme = useColorScheme() @@ -125,6 +128,7 @@ export const SegmentedControl: FC = ({ accessibilityValue={accessibilityValue} accessibilityRole={'tab'} accessibilityState={{ selected: isSelected }} + testID={testIDs?.[index]} > {label}