Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toggle): make props.labelText optional #13196

Merged
merged 4 commits into from
Mar 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(toggle): add 'with accessible labels' story
janhassel committed Feb 21, 2023
commit 0822fc9f7d33218a26754ce5e5f49c1bf241fc68
28 changes: 27 additions & 1 deletion packages/react/src/components/Toggle/Toggle.stories.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
*/

import React from 'react';

import { VStack } from '../Stack';
import Toggle from '../Toggle';

export default {
@@ -35,7 +37,7 @@ export const SmallToggle = () => (
);

export const Playground = (args) => (
<Toggle labelA="Off" labelB="On" defaultToggled id="toggle-1" {...args} />
<Toggle labelA="Off" labelB="On" defaultToggled id="toggle-3" {...args} />
);

Playground.argTypes = {
@@ -80,3 +82,27 @@ Playground.argTypes = {
},
},
};

export const WithAcessibleLabels = () => (
<VStack gap={7}>
<Toggle id="toggle-4" labelText="Toggle label" />

<Toggle id="toggle-5" labelText="Toggle label" hideLabel />

<div>
<div id="toggle-6-label" style={{ marginBlockEnd: '0.5rem' }}>
External toggle label
</div>
<Toggle id="toggle-6" aria-labelledby="toggle-6-label" hideLabel />
</div>

<div>
<label
htmlFor="toggle-7"
style={{ display: 'block', marginBlockEnd: '0.5rem' }}>
External toggle label
</label>
<Toggle id="toggle-7" hideLabel />
</div>
</VStack>
);