Skip to content

Commit 28febfa

Browse files
committed
feat: add data-testid to toggle-switch component [LW-11556]
1 parent 57d4126 commit 28febfa

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,36 @@ 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 className={cx.label} htmlFor={id} data-testid={testId + '-label'}>
3941
<Text.Body.Normal color="secondary">{label}</Text.Body.Normal>
4042
</label>
41-
{icon !== undefined && <Box className={cx.iconContainer}>{icon}</Box>}
43+
{icon !== undefined && (
44+
<Box className={cx.iconContainer} testId={testId + '-icon'}>
45+
{icon}
46+
</Box>
47+
)}
4248
<Switch.Root
4349
{...props}
4450
disabled={disabled}
4551
className={cx.toogleSwitch}
4652
id={id}
53+
data-testid={testId + '-switch'}
4754
>
4855
<Switch.Thumb className={cx.thumb} />
4956
</Switch.Root>

0 commit comments

Comments
 (0)