Skip to content

Commit 65d3a58

Browse files
authored
Merge pull request #55 from input-output-hk/LW-11556/add_test_ids
add data-testid to toggle-switch component
2 parents 57d4126 + 6726320 commit 65d3a58

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/design-system/box/box.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const Box = forwardRef<HTMLDivElement | null, Readonly<Props>>(
5151
px,
5252
py,
5353
w,
54-
testId = 'box',
54+
testId,
5555
...props
5656
},
5757
ref,

src/design-system/toggle-switch/toggle-switch.component.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,40 @@ type Props = Omit<
2121
defaultChecked?: boolean;
2222
required?: boolean;
2323
id?: string;
24+
testId?: string;
2425
};
2526

2627
export const ToggleSwitch = ({
2728
label,
2829
id,
2930
icon,
3031
disabled,
32+
testId,
3133
...props
3234
}: Readonly<Props>): JSX.Element => {
3335
return (
3436
<Flex
3537
alignItems="center"
3638
className={disabled === true ? cx.disabled : undefined}
3739
>
38-
<label className={cx.label} htmlFor={id}>
40+
<label
41+
className={cx.label}
42+
htmlFor={id}
43+
data-testid={testId + 'toggle-label'}
44+
>
3945
<Text.Body.Normal color="secondary">{label}</Text.Body.Normal>
4046
</label>
41-
{icon !== undefined && <Box className={cx.iconContainer}>{icon}</Box>}
47+
{icon !== undefined && (
48+
<Box className={cx.iconContainer} testId={testId + 'toggle-icon'}>
49+
{icon}
50+
</Box>
51+
)}
4252
<Switch.Root
4353
{...props}
4454
disabled={disabled}
4555
className={cx.toogleSwitch}
4656
id={id}
57+
data-testid={testId + 'toggle-switch'}
4758
>
4859
<Switch.Thumb className={cx.thumb} />
4960
</Switch.Root>

0 commit comments

Comments
 (0)