Skip to content

Commit ca1db5d

Browse files
author
Sine Jespersen
committed
5389: add hidden label example
1 parent 3b3abe2 commit ca1db5d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/stories/Library/Forms/checkbox/Checkbox.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ Unchecked.args = {
4646
validation: "Error error error",
4747
};
4848

49+
export const hiddenLabel = Template.bind({});
50+
hiddenLabel.args = {
51+
isChecked: true,
52+
label: "Checkbox",
53+
hiddenLabel: true,
54+
};
55+
4956
// Show multiple checkboxes to make it easier to test keyboard navigation.
5057
const Several: ComponentStory<typeof Checkbox> = (args) => (
5158
<>

src/stories/Library/Forms/checkbox/Checkbox.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type CheckboxProps = {
66
ariaLabel?: string;
77
validation?: string;
88
callback?: (isChecked: boolean) => void;
9+
hiddenLabel: boolean;
910
};
1011

1112
export const Checkbox: React.FC<CheckboxProps> = ({
@@ -14,6 +15,7 @@ export const Checkbox: React.FC<CheckboxProps> = ({
1415
ariaLabel,
1516
callback,
1617
validation,
18+
hiddenLabel = false,
1719
}) => {
1820
const checkboxId = useRef(`checkbox_id__${Math.random()}`);
1921
const [checked, setChecked] = useState(isChecked);
@@ -50,7 +52,11 @@ export const Checkbox: React.FC<CheckboxProps> = ({
5052
</span>
5153
<div>
5254
{label && (
53-
<span className="checkbox__text text-small-caption color-secondary-gray">
55+
<span
56+
className={`checkbox__text text-small-caption color-secondary-gray ${
57+
hiddenLabel ? "checkbox__text--hide-visually" : ""
58+
}`}
59+
>
5460
{label}
5561
</span>
5662
)}

0 commit comments

Comments
 (0)