Skip to content

Commit

Permalink
Add id to the checkbox and wrap the icon and label text with a labe…
Browse files Browse the repository at this point in the history
…l using `htmlFor`

to toggle the checkbox when clicking on the box/icon and label text.
  • Loading branch information
kasperbirch1 committed Nov 9, 2023
1 parent 29321fd commit c1657bc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/components/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const CheckBox: FC<CheckBoxProps> = ({
// This is to handle focus when more items are loaded via pagination
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={focused}
id={id}
data-cy={id}
className="checkbox__input"
onChange={(e) => {
Expand All @@ -51,23 +52,22 @@ const CheckBox: FC<CheckBoxProps> = ({
aria-labelledby={isVisualOnly && labelledBy ? labelledBy : undefined}
disabled={disabled}
/>
<div className="checkbox__label" id={id}>
<label className="checkbox__label" htmlFor={id}>
<span className="checkbox__icon" aria-labelledby={labelledBy}>
<IconCheckbox />
</span>
{label && (
<label
<span
id={id}
htmlFor={id}
data-cy="checkbox-text"
className={`checkbox__text text-small-caption color-secondary-gray ${
hideLabel ? "checkbox__text--hide-visually" : ""
}`}
>
{label}
</label>
</span>
)}
</div>
</label>
</div>
);
};
Expand Down

0 comments on commit c1657bc

Please sign in to comment.