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

chore: Add Field (Set) examples to Checkbox, Select and Time Input #1566

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions packages/css/src/components/field/field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

.ams-field {
align-items: start;
break-inside: avoid;
display: flex;
flex-direction: column;
Expand Down
21 changes: 21 additions & 0 deletions storybook/src/components/Checkbox/Checkbox.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,24 @@ import README from "../../../../packages/css/src/components/checkbox/README.md?r
### Long label

<Canvas of={CheckboxStories.LongLabel} />

### In a Field Set

Use a Field Set to group several Checkboxes with a legend, description and / or an Error Message.

Because of an [NVDA bug](https://github.com/nvaccess/nvda/issues/12718), we add the description text to the Field Set with `aria-labelledby`,
instead of `aria-describedby`.

If you don’t need the description, remove its Paragraph and the Paragraphs `id` from the Field Set `aria-labelledby`.

Check [the Field Set docs](/docs/components-forms-field-set--docs) for more information on configuring it.

<Canvas of={CheckboxStories.InAFieldSet} />

### In a Field Set with validation

If the Checkbox can become invalid, add an Error Message component and its `id` to the `aria-labelledby` attribute of the Field Set.

Check [the Field Set docs](/docs/components-forms-field-set--docs) for more information on configuring it.

<Canvas of={CheckboxStories.InAFieldSetWithValidation} />
100 changes: 100 additions & 0 deletions storybook/src/components/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright Gemeente Amsterdam
*/

import { Column, ErrorMessage, FieldSet, Paragraph } from '@amsterdam/design-system-react'
import { Checkbox } from '@amsterdam/design-system-react/src'
import { useArgs } from '@storybook/preview-api'
import { Meta, StoryObj } from '@storybook/react'
Expand Down Expand Up @@ -56,3 +57,102 @@ export const LongLabel: Story = {
'Ik heb alle gegevens correct en volledig ingevuld. Ik begrijp dat een verhuizing via internet dezelfde juridische status heeft als een verhuizing met een geschreven geldige handtekening.',
},
}

export const InAFieldSet: Story = {
argTypes: {
checked: {
table: { disable: true },
},
children: {
table: { disable: true },
},
disabled: {
table: { disable: true },
},
indeterminate: {
table: { disable: true },
},
},
render: ({ invalid }) => (
<FieldSet
aria-labelledby={`fieldset1 description1${invalid ? ' error1' : ''}`}
id="fieldset1"
invalid={invalid}
legend="Waar gaat uw melding over?"
>
<Paragraph className="ams-mb--sm" id="description1" size="small">
De laatstgenoemde melding.
</Paragraph>
{invalid && (
<ErrorMessage className="ams-mb--sm" id="error1">
Geef aan waar uw laatstgenoemde melding over gaat.
</ErrorMessage>
)}
<Column gap="extra-small">
<Checkbox invalid={invalid} name="about" value="horeca">
Horecabedrijf
</Checkbox>
<Checkbox invalid={invalid} name="about" value="ander_bedrijf">
Ander soort bedrijf
</Checkbox>
<Checkbox invalid={invalid} name="about" value="evenement">
Evenement
</Checkbox>
<Checkbox invalid={invalid} name="about" value="anders">
Iets anders
</Checkbox>
</Column>
</FieldSet>
),
}

export const InAFieldSetWithValidation: Story = {
args: {
invalid: true,
},
argTypes: {
checked: {
table: { disable: true },
},
children: {
table: { disable: true },
},
disabled: {
table: { disable: true },
},
indeterminate: {
table: { disable: true },
},
},
render: ({ invalid }) => (
<FieldSet
aria-labelledby={`fieldset2 description2${invalid ? ' error2' : ''}`}
id="fieldset2"
invalid={invalid}
legend="Waar gaat uw melding over?"
>
<Paragraph className="ams-mb--sm" id="description2" size="small">
De laatstgenoemde melding.
</Paragraph>
{invalid && (
<ErrorMessage className="ams-mb--sm" id="error2">
Geef aan waar uw laatstgenoemde melding over gaat.
</ErrorMessage>
)}
<Column gap="extra-small">
<Checkbox invalid={invalid} name="about" value="horeca">
Horecabedrijf
</Checkbox>
<Checkbox invalid={invalid} name="about" value="ander_bedrijf">
Ander soort bedrijf
</Checkbox>
<Checkbox invalid={invalid} name="about" value="evenement">
Evenement
</Checkbox>
<Checkbox invalid={invalid} name="about" value="anders">
Iets anders
</Checkbox>
</Column>
</FieldSet>
),
}
2 changes: 1 addition & 1 deletion storybook/src/components/Radio/Radio.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import README from "../../../../packages/css/src/components/radio/README.md?raw"

### In a Field Set

Use a Field Set to group several Radios with a legend, description and / or an error message.
Use a Field Set to group several Radios with a legend, description and / or an Error Message.

Add `role="radiogroup"` to the Field Set to have it explicitly announced as a radio group (the default role is just ‘group’).
The ‘radio group’ role also allows using `aria-required` on Field Set; that isn’t allowed for the ‘group’ role.
Expand Down
18 changes: 18 additions & 0 deletions storybook/src/components/Select/Select.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,21 @@ The component requires a `label` attribute.
### Disabled

<Canvas of={SelectStories.Disabled} />

### In a Field

Use a Field to group a Select with a Label, description and / or an Error Message.

If you don’t need the description, remove its Paragraph and the `aria-describedby` from the Select.

Check [the Field docs](/docs/components-forms-field--docs) for more information on configuring it.

<Canvas of={SelectStories.InAField} />

### In a Field with validation

If the Select can become invalid, add an Error Message and its `id` to the `aria-describedby` attribute of the Select.

Check [the Field docs](/docs/components-forms-field--docs) for more information on configuring it.

<Canvas of={SelectStories.InAFieldWithValidation} />
82 changes: 59 additions & 23 deletions storybook/src/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,41 @@
* Copyright Gemeente Amsterdam
*/

import { ErrorMessage, Field, Label, Paragraph } from '@amsterdam/design-system-react'
import { Select } from '@amsterdam/design-system-react/src'
import { Meta, StoryObj } from '@storybook/react'

const optionList = [
<Select.Option key="1" value="1">
Centrum
</Select.Option>,
<Select.Option key="2" value="2">
Noord
</Select.Option>,
<Select.Option key="3" value="3">
West
</Select.Option>,
<Select.Option key="4" value="4" disabled>
Westpoort
</Select.Option>,
<Select.Option key="6" value="5">
Nieuw-West
</Select.Option>,
<Select.Option key="7" value="6">
Zuid
</Select.Option>,
<Select.Option key="8" value="7">
Zuidoost
</Select.Option>,
]

const meta = {
title: 'Components/Forms/Select',
component: Select,
args: {
invalid: false,
disabled: false,
children: [
<Select.Option key="1" value="1">
Centrum
</Select.Option>,
<Select.Option key="2" value="2">
Noord
</Select.Option>,
<Select.Option key="3" value="3">
West
</Select.Option>,
<Select.Option key="4" value="4" disabled>
Westpoort
</Select.Option>,
<Select.Option key="6" value="5">
Nieuw-West
</Select.Option>,
<Select.Option key="7" value="6">
Zuid
</Select.Option>,
<Select.Option key="8" value="7">
Zuidoost
</Select.Option>,
],
children: optionList,
},
argTypes: {
disabled: {
Expand Down Expand Up @@ -111,3 +114,36 @@ export const Disabled: Story = {
disabled: true,
},
}

export const InAField: Story = {
render: (args) => (
<Field invalid={args.invalid}>
<Label htmlFor="input1">Label</Label>
<Paragraph id="description1" size="small">
Omschrijving.
</Paragraph>
{args.invalid && <ErrorMessage id="error1">Foutmelding.</ErrorMessage>}
<Select aria-describedby={`description1${args.invalid ? ' error1' : ''}`} id="input1" {...args}>
{optionList}
</Select>
</Field>
),
}

export const InAFieldWithValidation: Story = {
args: {
invalid: true,
},
render: (args) => (
<Field invalid={args.invalid}>
<Label htmlFor="input2">Label</Label>
<Paragraph id="description2" size="small">
Omschrijving.
</Paragraph>
{args.invalid && <ErrorMessage id="error2">Foutmelding.</ErrorMessage>}
<Select aria-describedby={`description2${args.invalid ? ' error2' : ''}`} id="input2" {...args}>
{optionList}
</Select>
</Field>
),
}
18 changes: 18 additions & 0 deletions storybook/src/components/TimeInput/TimeInput.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ import README from "../../../../packages/css/src/components/time-input/README.md
### Disabled

<Canvas of={TimeInputStories.Disabled} />

### In a Field

Use a Field to group a Time Input with a Label, description and / or an Error Message.

If you don’t need the description, remove its Paragraph and the `aria-describedby` from the Time Input.

Check [the Field docs](/docs/components-forms-field--docs) for more information on configuring it.

<Canvas of={TimeInputStories.InAField} />

### In a Field with validation

If the Time Input can become invalid, add an Error Message and its `id` to the `aria-describedby` attribute of the Time Input.

Check [the Field docs](/docs/components-forms-field--docs) for more information on configuring it.

<Canvas of={TimeInputStories.InAFieldWithValidation} />
30 changes: 30 additions & 0 deletions storybook/src/components/TimeInput/TimeInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright Gemeente Amsterdam
*/

import { ErrorMessage, Field, Label, Paragraph } from '@amsterdam/design-system-react'
import { TimeInput } from '@amsterdam/design-system-react/src'
import { Meta, StoryObj } from '@storybook/react'

Expand Down Expand Up @@ -37,3 +38,32 @@ export const Disabled: Story = {
disabled: true,
},
}

export const InAField: Story = {
render: (args) => (
<Field invalid={args.invalid}>
<Label htmlFor="input1">Label</Label>
<Paragraph id="description1" size="small">
Omschrijving.
</Paragraph>
{args.invalid && <ErrorMessage id="error1">Foutmelding.</ErrorMessage>}
<TimeInput aria-describedby={`description1${args.invalid ? ' error1' : ''}`} id="input1" {...args} />
</Field>
),
}

export const InAFieldWithValidation: Story = {
args: {
invalid: true,
},
render: (args) => (
<Field invalid={args.invalid}>
<Label htmlFor="input2">Label</Label>
<Paragraph id="description2" size="small">
Omschrijving.
</Paragraph>
{args.invalid && <ErrorMessage id="error2">Foutmelding.</ErrorMessage>}
<TimeInput aria-describedby={`description2${args.invalid ? ' error2' : ''}`} id="input2" {...args} />
</Field>
),
}