Skip to content

Commit 68e49e0

Browse files
committed
feat: add testIDs to ItemText component
1 parent 4a039d6 commit 68e49e0

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/design-system/select/select-item/select-item-text.component.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import { Text } from '../../text';
88
export interface SelectItemTitleProps {
99
title: string;
1010
description?: string;
11+
testId?: string;
1112
}
1213

1314
/**
1415
* @param title Item title that will be displayed in the trigger/container after when this item is selected.
1516
* @param [description] Item description, visible only when input is in `open` state.
1617
*/
1718
export const ItemText = forwardRef<HTMLSpanElement, SelectItemTitleProps>(
18-
({ title, description }, forwardReference) => (
19+
({ title, description, testId }, forwardReference) => (
1920
<Flex flexDirection="row" alignItems="center" gap="$24">
2021
{/* Please do not attempt to use our <Text.* /> component. Radix forbids the styling of ItemText.
2122
See: https://www.radix-ui.com/primitives/docs/components/select#itemtext */}
22-
<Select.ItemText ref={forwardReference}>{title}</Select.ItemText>
23+
<Select.ItemText ref={forwardReference} data-testid={testId}>
24+
{title}
25+
</Select.ItemText>
2326
{Boolean(description) && <Text.Body.Large>{description}</Text.Body.Large>}
2427
</Flex>
2528
),

src/design-system/select/select-item/select-item.component.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export const Item = forwardRef<HTMLDivElement, SelectItemProps>(
3737
variant={variant}
3838
testId={testId}
3939
>
40-
<ItemText title={title} description={description} />
40+
<ItemText
41+
title={title}
42+
description={description}
43+
testId={`${testId ?? 'item'}-text`}
44+
/>
4145
<ItemIndicator testId={`${testId ?? 'select'}-indicator`} />
4246
</ItemRoot>
4347
),

src/design-system/select/select.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ Interactions.play = async ({ canvasElement }): Promise<void> => {
441441

442442
await sleep(pauseBetweenClicksInMs);
443443

444-
expect(canvas.getByTestId(optionTestId)).toBeInTheDocument();
444+
expect(canvas.getByTestId(`${optionTestId}-text`)).toBeInTheDocument();
445445
userEvent.click(canvas.getByTestId(optionTestId));
446446

447447
await sleep(pauseBetweenClicksInMs);

0 commit comments

Comments
 (0)