@workday/canvas-kit-docs 16.2.1 → 16.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es6/lib/docs.js +2 -2
- package/dist/es6/lib/stackblitzFiles/packageJSONFile.js +5 -5
- package/dist/es6/lib/stackblitzFiles/packageJSONFile.ts +5 -5
- package/dist/mdx/preview-react/radio/Radio.mdx +133 -18
- package/dist/mdx/preview-react/radio/examples/Required.tsx +0 -1
- package/dist/mdx/preview-react/switch/Switch.mdx +119 -0
- package/dist/mdx/preview-react/switch/examples/Basic.tsx +1 -1
- package/package.json +6 -6
package/dist/es6/lib/docs.js
CHANGED
|
@@ -94223,7 +94223,7 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
94223
94223
|
]
|
|
94224
94224
|
},
|
|
94225
94225
|
"required": false,
|
|
94226
|
-
"description": "
|
|
94226
|
+
"description": "The id of hint or error text associated with each radio.\n\nDo not set this when radios are wrapped in `FormFieldGroup.Input`. `FormFieldGroup.Input`\nwrites `aria-describedby=\"hint-{id}\"` on each radio, and that value overrides\n`aria-describedby` set on `RadioGroup`. Put the message in `FormFieldGroup.Hint`.\n\n```tsx\n<FormFieldGroup error=\"caution\">\n <FormFieldGroup.Label>Choose Your Pizza Crust</FormFieldGroup.Label>\n <FormFieldGroup.Field>\n <FormFieldGroup.List as={RadioGroup} name=\"crust\" value={value} onChange={handleChange}>\n <FormFieldGroup.Input as={RadioGroup.RadioButton} value=\"deep-dish\">\n Deep dish\n </FormFieldGroup.Input>\n <FormFieldGroup.Input as={RadioGroup.RadioButton} value=\"thin\">\n Thin\n </FormFieldGroup.Input>\n </FormFieldGroup.List>\n <FormFieldGroup.Hint>Deep dish is an extra $2.99.</FormFieldGroup.Hint>\n </FormFieldGroup.Field>\n</FormFieldGroup>\n```",
|
|
94227
94227
|
"declarations": [
|
|
94228
94228
|
{
|
|
94229
94229
|
"name": "aria-describedby",
|
|
@@ -94574,7 +94574,7 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
94574
94574
|
]
|
|
94575
94575
|
},
|
|
94576
94576
|
"required": false,
|
|
94577
|
-
"description": "
|
|
94577
|
+
"description": "The id of hint or error text associated with each radio.\n\nDo not set this when radios are wrapped in `FormFieldGroup.Input`. `FormFieldGroup.Input`\nwrites `aria-describedby=\"hint-{id}\"` on each radio, and that value overrides\n`aria-describedby` set on `RadioGroup`. Put the message in `FormFieldGroup.Hint`.\n\n```tsx\n<FormFieldGroup error=\"caution\">\n <FormFieldGroup.Label>Choose Your Pizza Crust</FormFieldGroup.Label>\n <FormFieldGroup.Field>\n <FormFieldGroup.List as={RadioGroup} name=\"crust\" value={value} onChange={handleChange}>\n <FormFieldGroup.Input as={RadioGroup.RadioButton} value=\"deep-dish\">\n Deep dish\n </FormFieldGroup.Input>\n <FormFieldGroup.Input as={RadioGroup.RadioButton} value=\"thin\">\n Thin\n </FormFieldGroup.Input>\n </FormFieldGroup.List>\n <FormFieldGroup.Hint>Deep dish is an extra $2.99.</FormFieldGroup.Hint>\n </FormFieldGroup.Field>\n</FormFieldGroup>\n```",
|
|
94578
94578
|
"declarations": [
|
|
94579
94579
|
{
|
|
94580
94580
|
"name": "aria-describedby",
|
|
@@ -18,11 +18,11 @@ export const packageJSONFile = `{
|
|
|
18
18
|
"@emotion/react": "11.11.4",
|
|
19
19
|
"@types/react": "18.2.60",
|
|
20
20
|
"@types/react-dom": "18.2.19",
|
|
21
|
-
"@workday/canvas-kit-labs-react": "16.2.
|
|
22
|
-
"@workday/canvas-kit-preview-react": "16.2.
|
|
23
|
-
"@workday/canvas-kit-react": "16.2.
|
|
24
|
-
"@workday/canvas-kit-react-fonts": "^16.2.
|
|
25
|
-
"@workday/canvas-kit-styling": "16.2.
|
|
21
|
+
"@workday/canvas-kit-labs-react": "16.2.3",
|
|
22
|
+
"@workday/canvas-kit-preview-react": "16.2.3",
|
|
23
|
+
"@workday/canvas-kit-react": "16.2.3",
|
|
24
|
+
"@workday/canvas-kit-react-fonts": "^16.2.3",
|
|
25
|
+
"@workday/canvas-kit-styling": "16.2.3",
|
|
26
26
|
"@workday/canvas-system-icons-web": "^5.0.3",
|
|
27
27
|
"@workday/canvas-expressive-icons-web": "1.0.1",
|
|
28
28
|
"@workday/canvas-tokens-web": "4.4.0-beta.11"
|
|
@@ -19,11 +19,11 @@ export const packageJSONFile = `{
|
|
|
19
19
|
"@emotion/react": "11.11.4",
|
|
20
20
|
"@types/react": "18.2.60",
|
|
21
21
|
"@types/react-dom": "18.2.19",
|
|
22
|
-
"@workday/canvas-kit-labs-react": "16.2.
|
|
23
|
-
"@workday/canvas-kit-preview-react": "16.2.
|
|
24
|
-
"@workday/canvas-kit-react": "16.2.
|
|
25
|
-
"@workday/canvas-kit-react-fonts": "^16.2.
|
|
26
|
-
"@workday/canvas-kit-styling": "16.2.
|
|
22
|
+
"@workday/canvas-kit-labs-react": "16.2.3",
|
|
23
|
+
"@workday/canvas-kit-preview-react": "16.2.3",
|
|
24
|
+
"@workday/canvas-kit-react": "16.2.3",
|
|
25
|
+
"@workday/canvas-kit-react-fonts": "^16.2.3",
|
|
26
|
+
"@workday/canvas-kit-styling": "16.2.3",
|
|
27
27
|
"@workday/canvas-system-icons-web": "^5.0.3",
|
|
28
28
|
"@workday/canvas-expressive-icons-web": "1.0.1",
|
|
29
29
|
"@workday/canvas-tokens-web": "4.4.0-beta.11"
|
|
@@ -2,14 +2,14 @@ import {ExampleCodeBlock, SymbolDoc} from '@workday/canvas-kit-docs';
|
|
|
2
2
|
|
|
3
3
|
import Basic from './examples/Basic';
|
|
4
4
|
import Caution from './examples/Caution';
|
|
5
|
+
import Custom from './examples/Custom';
|
|
6
|
+
import Disabled from './examples/Disabled';
|
|
5
7
|
import Error from './examples/Error';
|
|
6
8
|
import Inverse from './examples/Inverse';
|
|
7
9
|
import LabelPosition from './examples/LabelPosition';
|
|
8
10
|
import NoValue from './examples/NoValue';
|
|
9
11
|
import RefForwarding from './examples/RefForwarding';
|
|
10
|
-
import Disabled from './examples/Disabled';
|
|
11
12
|
import Required from './examples/Required';
|
|
12
|
-
import Custom from './examples/Custom';
|
|
13
13
|
import StandaloneRadio from './examples/StandaloneRadio';
|
|
14
14
|
|
|
15
15
|
|
|
@@ -32,22 +32,20 @@ yarn add @workday/canvas-kit-preview-react
|
|
|
32
32
|
Our radio component includes a `RadioGroup` container and `RadioGroup.RadioButton`, which renders an
|
|
33
33
|
individual radio button. Nest related `RadioGroup.RadioButton` buttons within a `RadioGroup` and
|
|
34
34
|
provide a `name` prop to the `RadioGroup` to group the radio buttons together. Each
|
|
35
|
-
`RadioGroup.
|
|
36
|
-
prop set on the `RadioGroup` to determine which radio button is selected. To tie it all
|
|
37
|
-
provide an `onChange` handler to the `RadioGroup` to track the selected value as it
|
|
35
|
+
`RadioGroup.RadioButton` must have a unique `value`. This value is used in conjunction with the
|
|
36
|
+
`value` prop set on the `RadioGroup` to determine which radio button is selected. To tie it all
|
|
37
|
+
together, provide an `onChange` handler to the `RadioGroup` to track the selected value as it
|
|
38
|
+
changes.
|
|
38
39
|
|
|
39
|
-
`RadioGroup` should be used in tandem with
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
`RadioGroup` should be used in tandem with
|
|
41
|
+
[FormFieldGroup](/components/inputs/form-field/#accessibility). `FormFieldGroup.Label` names the
|
|
42
|
+
group, and `FormFieldGroup.Input` associates hint, error, and required state with each radio.
|
|
42
43
|
|
|
43
44
|
<ExampleCodeBlock code={Basic} />
|
|
44
45
|
|
|
45
46
|
Our example uses [React state](<(https://react.dev/learn/state-a-components-memory)>) to track the
|
|
46
47
|
value of the `RadioGroup`.
|
|
47
48
|
|
|
48
|
-
`RadioGroup` and `RadioGroup.Radio` support keyboard navigation through the proper use of WAI-ARIA
|
|
49
|
-
[properties](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/radiogroup_role#associated_wai-aria_roles_states_and_properties).
|
|
50
|
-
|
|
51
49
|
### Inverse
|
|
52
50
|
|
|
53
51
|
Set the `variant` prop of `RadioGroup.RadioButton` to `inverse` to ensure proper contrast on dark
|
|
@@ -78,7 +76,7 @@ input component. By default, the orientation will be set to `vertical`.
|
|
|
78
76
|
|
|
79
77
|
### Required
|
|
80
78
|
|
|
81
|
-
Set the `
|
|
79
|
+
Set the `isRequired` prop of the wrapping `FormFieldGroup` to `true` to indicate that the field is
|
|
82
80
|
required. Labels for required fields are suffixed by a red asterisk.
|
|
83
81
|
|
|
84
82
|
<ExampleCodeBlock code={Required} />
|
|
@@ -110,12 +108,9 @@ some behavior handled for you.
|
|
|
110
108
|
|
|
111
109
|
### Error States
|
|
112
110
|
|
|
113
|
-
Set the `error` prop of the wrapping `
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
standards. You must set an `aria-describedby` attribute on the `RadioGroup` element that matches the
|
|
117
|
-
value of `hintId` set on the `FormField` element. These attributes ensure that the alert message is
|
|
118
|
-
associated to the `RadioGroup` and read out by voiceover.
|
|
111
|
+
Set the `error` prop of the wrapping `FormFieldGroup` to `"caution"` or `"error"` to set the group
|
|
112
|
+
to the alert or error state. Put the message in `FormFieldGroup.Hint`. `FormFieldGroup.Input`
|
|
113
|
+
associates that text with each radio.
|
|
119
114
|
|
|
120
115
|
#### Caution
|
|
121
116
|
|
|
@@ -141,6 +136,126 @@ Radio and its subcomponents support custom styling via the `cs` prop. For more i
|
|
|
141
136
|
our
|
|
142
137
|
["How To Customize Styles"](https://workday.github.io/canvas-kit/?path=/docs/styling-guides-customizing-styles--docs).
|
|
143
138
|
|
|
139
|
+
## Accessibility
|
|
140
|
+
|
|
141
|
+
The primary accessibility goal is to ensure users can identify the radio group and each option,
|
|
142
|
+
determine which option is selected, and hear associated hints, errors, and required state when a
|
|
143
|
+
radio receives focus. Use **Radio** when the user must choose one option from a list. For
|
|
144
|
+
independent options, use
|
|
145
|
+
[**Checkbox**](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-checkbox--docs)
|
|
146
|
+
instead.
|
|
147
|
+
|
|
148
|
+
### Minimum Accessible Structure
|
|
149
|
+
|
|
150
|
+
The following matches the [Basic Example](#basic-example): a **`FormFieldGroup`** with
|
|
151
|
+
**`FormFieldGroup.List as={RadioGroup}`**, and two or more
|
|
152
|
+
**`FormFieldGroup.Input as={RadioGroup.RadioButton}`** options.
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
import {RadioGroup} from '@workday/canvas-kit-preview-react/radio';
|
|
156
|
+
import {FormFieldGroup} from '@workday/canvas-kit-react/form-field';
|
|
157
|
+
|
|
158
|
+
<FormFieldGroup>
|
|
159
|
+
<FormFieldGroup.Label>Choose Your Pizza Crust</FormFieldGroup.Label>
|
|
160
|
+
<FormFieldGroup.Field>
|
|
161
|
+
<FormFieldGroup.List as={RadioGroup}>
|
|
162
|
+
<FormFieldGroup.Input as={RadioGroup.RadioButton}>Deep dish</FormFieldGroup.Input>
|
|
163
|
+
<FormFieldGroup.Input as={RadioGroup.RadioButton}>Thin</FormFieldGroup.Input>
|
|
164
|
+
</FormFieldGroup.List>
|
|
165
|
+
</FormFieldGroup.Field>
|
|
166
|
+
</FormFieldGroup>;
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Each option needs visible text. See the [Basic Example](#basic-example) for selection behavior.
|
|
170
|
+
|
|
171
|
+
### Built-in Behaviors
|
|
172
|
+
|
|
173
|
+
Canvas Kit applies these automatically when you compose **`FormFieldGroup`** with **`RadioGroup`**.
|
|
174
|
+
**Do not duplicate them** in consuming code.
|
|
175
|
+
|
|
176
|
+
**ARIA and DOM** (_applied by `RadioGroup` and `FormFieldGroup`_):
|
|
177
|
+
|
|
178
|
+
- **`RadioGroup`**: Renders a `div`. It does not set `role="radiogroup"`.
|
|
179
|
+
- **`RadioGroup.RadioButton`**: Renders a `<label>` around `<input type="radio">` and the visible
|
|
180
|
+
text. The wrapping `<label>` is the association, so an `htmlFor` pairing is not needed. That text
|
|
181
|
+
is the option's accessible name, and clicking it selects the radio.
|
|
182
|
+
|
|
183
|
+
**Keyboard** (_native radio behavior_):
|
|
184
|
+
|
|
185
|
+
**`RadioGroup`** uses native radio keyboard behavior. <kbd>Tab</kbd> moves to the selected radio, or
|
|
186
|
+
to the first radio when none is selected, and then leaves the group. Arrow keys move and select
|
|
187
|
+
within the group.
|
|
188
|
+
|
|
189
|
+
**Screen reader expectations** (_when built-in behaviors are used as intended_):
|
|
190
|
+
|
|
191
|
+
- On focus, assistive technology announces the group name from **`FormFieldGroup.Label`**, along
|
|
192
|
+
with the option name, radio role, and checked state.
|
|
193
|
+
- When applicable, it also announces required state, invalid state (`error="error"`), and hint or
|
|
194
|
+
error text. Caution does not set `aria-invalid`.
|
|
195
|
+
- Disabled radios are announced as unavailable.
|
|
196
|
+
|
|
197
|
+
For group, hint, error, and required association, see
|
|
198
|
+
[FormField's Built-in Behaviors](/components/inputs/form-field/#built-in-behaviors).
|
|
199
|
+
|
|
200
|
+
### Accessibility Requirements
|
|
201
|
+
|
|
202
|
+
Required in application code for an accessible Radio group. Rows marked _(conditional)_ apply only
|
|
203
|
+
when the situation matches—otherwise omit.
|
|
204
|
+
|
|
205
|
+
**If no design spec is provided:** use a visible **`FormFieldGroup.Label`**. On
|
|
206
|
+
**`FormFieldGroup.List as={RadioGroup}`**, set a shared **`name`** and render two or more
|
|
207
|
+
**`RadioGroup.RadioButton`** options with visible text and their own **`value`**. Omit **`error`**,
|
|
208
|
+
**`isRequired`**, **`FormFieldGroup.Hint`**, **`disabled`**, **`aria-describedby`** on
|
|
209
|
+
**`RadioGroup`**, **`error`** on **`RadioGroup`**, a **`ref`**, and **`StyledRadioButton`** unless
|
|
210
|
+
the spec requires them.
|
|
211
|
+
|
|
212
|
+
**Programmatic focus** _(conditional — omit by default)_:
|
|
213
|
+
|
|
214
|
+
Attach a **`ref`** only when the product must move focus to a radio after an action. Do not attach a
|
|
215
|
+
**`ref`** or call `focus()` unless the design or developer asks for it. See
|
|
216
|
+
[Ref Forwarding](#ref-forwarding).
|
|
217
|
+
|
|
218
|
+
| Requirement | How to satisfy |
|
|
219
|
+
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
220
|
+
| Group and option names | Use **`FormFieldGroup`** with a visible **`FormFieldGroup.Label`**. Render **`FormFieldGroup.List as={RadioGroup}`** with a shared **`name`**, and give every **`FormFieldGroup.Input as={RadioGroup.RadioButton}`** visible text and its own **`value`**. The shared **`name`** groups the inputs, and each option **`value`** is what the selected state matches. See [Basic Example](#basic-example). |
|
|
221
|
+
| Error state _(conditional)_ | When the selection is invalid, set `error="error"` on **`FormFieldGroup`** and prefix **`FormFieldGroup.Hint`** with "Error:". See [Error States](#error-states). |
|
|
222
|
+
| Hint, caution, or required _(conditional)_ | On **`FormFieldGroup`**, use **`FormFieldGroup.Hint`** for hint text, `error="caution"` for caution, and **`isRequired`** for required state, only when the spec includes that state. See [Required](#required) and [FormField accessibility](/components/inputs/form-field/#accessibility). |
|
|
223
|
+
| Disabled _(conditional)_ | Set **`disabled`** on an unavailable **`RadioGroup.RadioButton`**. Never disable the selected radio. See [Disabled](#disabled). |
|
|
224
|
+
|
|
225
|
+
**Summary for code generation:**
|
|
226
|
+
|
|
227
|
+
- **REQUIRED:** **`FormFieldGroup`**, visible **`FormFieldGroup.Label`**,
|
|
228
|
+
**`FormFieldGroup.List as={RadioGroup}`** with a shared **`name`**, and two or more
|
|
229
|
+
**`RadioGroup.RadioButton`** options, each with visible text and its own **`value`**
|
|
230
|
+
- **CONDITIONAL:** when the selection is invalid, `error="error"` on **`FormFieldGroup`** and
|
|
231
|
+
**`FormFieldGroup.Hint`** prefixed with "Error:". Hint text, `error="caution"`, and
|
|
232
|
+
**`isRequired`** only when the spec includes that state. Also **`disabled`** (not on the selected
|
|
233
|
+
radio). See [FormField accessibility](/components/inputs/form-field/#accessibility) for group
|
|
234
|
+
hint, caution, and required.
|
|
235
|
+
|
|
236
|
+
### Anti-Patterns
|
|
237
|
+
|
|
238
|
+
Do **not** generate code that does the following (see **Accessibility Requirements** above for what
|
|
239
|
+
to supply instead):
|
|
240
|
+
|
|
241
|
+
- Add `role="radiogroup"` to **`RadioGroup`** — **`FormFieldGroup`** provides the group semantics
|
|
242
|
+
- Manually set `aria-checked`, `aria-invalid`, `aria-required`, or `aria-describedby` —
|
|
243
|
+
**`RadioGroup`** and **`FormFieldGroup.Input`** wire these attributes
|
|
244
|
+
- Use **`FormField`** with `useFieldset`, or set `hintId` and `hintText` — group radios with
|
|
245
|
+
**`FormFieldGroup`** and put the message in **`FormFieldGroup.Hint`**
|
|
246
|
+
- Wrap radios in **`FormField.Input`** — use **`FormFieldGroup.Input as={RadioGroup.RadioButton}`**
|
|
247
|
+
- Use **`StyledRadioButton`** unless the spec requires a radio outside **`RadioGroup`**. In that
|
|
248
|
+
case supply accessible option and group names and the necessary behavior. See
|
|
249
|
+
[Standalone Radio Button](#standalone-radio-button)
|
|
250
|
+
- Intercept <kbd>Tab</kbd> or arrow keys — native radio behavior moves and selects within the group
|
|
251
|
+
- Set **`disabled`** on the selected radio — that removes the group's tab stop, so keyboard users
|
|
252
|
+
cannot move within the group. See [Disabled](#disabled)
|
|
253
|
+
- Set **`error`** on **`RadioGroup`** — set it on **`FormFieldGroup`** so Canvas Kit provides both
|
|
254
|
+
the visual and accessible error state. See [Error States](#error-states)
|
|
255
|
+
- Rely on color alone for an error or caution — include **`FormFieldGroup.Hint`**. Use
|
|
256
|
+
`error="error"` when the selection is invalid so `aria-invalid` is set. See
|
|
257
|
+
[Error States](#error-states)
|
|
258
|
+
|
|
144
259
|
## Component API
|
|
145
260
|
|
|
146
261
|
<SymbolDoc name="RadioGroup" fileName="/preview-react/" />
|
|
@@ -75,6 +75,125 @@ Switch supports right-to-left languages when specified in the CanvasProvider the
|
|
|
75
75
|
Switch supports custom styling via the `cs` prop. For more information, check our
|
|
76
76
|
["How To Customize Styles"](https://workday.github.io/canvas-kit/?path=/docs/styling-guides-customizing-styles--docs).
|
|
77
77
|
|
|
78
|
+
## Accessibility
|
|
79
|
+
|
|
80
|
+
The primary accessibility goal is a visible, programmatically determinable name and an on or off
|
|
81
|
+
state that assistive technology can expose. Use **Switch** for a single setting that takes effect
|
|
82
|
+
immediately when toggled (for example, "Dark Mode"). When the user selects one or more options that
|
|
83
|
+
are applied on form submission, use [**Checkbox**](/components/inputs/checkbox/) instead. **Switch**
|
|
84
|
+
does not render its own `<label>`, so it relies on **`FormField`** for its name, hint, error, and
|
|
85
|
+
required wiring — see [FormField's accessibility documentation](/components/inputs/form-field/#accessibility).
|
|
86
|
+
|
|
87
|
+
### Minimum Accessible Structure
|
|
88
|
+
|
|
89
|
+
The following matches the [Basic Example](#basic-example). Every **Switch** needs **`FormField`**, a
|
|
90
|
+
visible **`FormField.Label`**, and **`FormField.Input as={Switch}`** inside **`FormField.Field`**.
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import React from 'react';
|
|
94
|
+
|
|
95
|
+
import {Switch} from '@workday/canvas-kit-preview-react/switch';
|
|
96
|
+
import {FormField} from '@workday/canvas-kit-react/form-field';
|
|
97
|
+
|
|
98
|
+
const Example = () => {
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<FormField>
|
|
102
|
+
<FormField.Label>Dark Mode</FormField.Label>
|
|
103
|
+
<FormField.Field>
|
|
104
|
+
<FormField.Input as={Switch} />
|
|
105
|
+
</FormField.Field>
|
|
106
|
+
</FormField>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Built-in Behaviors
|
|
112
|
+
|
|
113
|
+
Canvas Kit applies these automatically when you compose **Switch** with **`FormField`**
|
|
114
|
+
subcomponents. **Do not duplicate them** in consuming code.
|
|
115
|
+
|
|
116
|
+
**ARIA and DOM** (_applied by Switch and FormField_):
|
|
117
|
+
|
|
118
|
+
- **`Switch`**: Renders a native `<input type="checkbox">` with `role="switch"`. The native `checked`
|
|
119
|
+
state is exposed to assistive technology as on or off, so no `aria-checked` is needed. Canvas Kit
|
|
120
|
+
assigns an `id` with `useUniqueId` unless you pass **`id`**.
|
|
121
|
+
- **Track, thumb, and check/x icon**: Purely visual. The icon is a Canvas Kit **`SystemIcon`**, whose
|
|
122
|
+
SVG markup sets `role="presentation"` and `focusable="false"`, so it is not announced.
|
|
123
|
+
- **`disabled`**: Maps to the native `disabled` attribute.
|
|
124
|
+
|
|
125
|
+
**Keyboard** (_native checkbox behavior_):
|
|
126
|
+
|
|
127
|
+
**`Switch`** uses native `<input type="checkbox">` keyboard behavior (tab order and Space to
|
|
128
|
+
toggle). Do not intercept <kbd>Space</kbd> or otherwise prevent the native toggle.
|
|
129
|
+
|
|
130
|
+
**Screen reader expectations** (_when built-in behaviors are used as intended_):
|
|
131
|
+
|
|
132
|
+
- On focus, assistive technology announces the **`FormField.Label`** text, the "switch" role, and
|
|
133
|
+
the on or off state; when applicable, required state, invalid state (`error="error"`), and
|
|
134
|
+
**`FormField.Hint`** text via `aria-describedby`
|
|
135
|
+
- Toggling announces the new on or off state
|
|
136
|
+
- The Caution state is visual only — `aria-invalid` is **not** set for `error="caution"`
|
|
137
|
+
- Disabled switches are skipped in the tab order and may be announced as unavailable
|
|
138
|
+
|
|
139
|
+
For label, hint, and error association details, see
|
|
140
|
+
[FormField's Built-in Behaviors](/components/inputs/form-field/#built-in-behaviors).
|
|
141
|
+
|
|
142
|
+
### Accessibility Requirements
|
|
143
|
+
|
|
144
|
+
Required in application code for an accessible **Switch**. Rows marked _(conditional)_ apply only
|
|
145
|
+
when the situation matches—otherwise omit.
|
|
146
|
+
|
|
147
|
+
**If no design spec is provided:** use a visible **`FormField.Label`**, wrap the control with
|
|
148
|
+
**`FormField.Input as={Switch}`** inside **`FormField.Field`**, and control it with **`checked`** and
|
|
149
|
+
**`onChange`**. Omit **`isRequired`**, **`error`**, **`FormField.Hint`**, **`disabled`**,
|
|
150
|
+
**`isHidden`**, a custom **`id`**, and a **`ref`** unless the spec requires them.
|
|
151
|
+
|
|
152
|
+
**Programmatic focus** _(conditional — omit by default)_:
|
|
153
|
+
|
|
154
|
+
Attach a `ref` only when the product must move focus to the Switch after an action. Do not attach a
|
|
155
|
+
`ref` or call `focus()` unless the design or developer asks for it. See
|
|
156
|
+
[Ref Forwarding](#ref-forwarding) under Usage for a complete Storybook example.
|
|
157
|
+
|
|
158
|
+
| Requirement | How to satisfy |
|
|
159
|
+
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
160
|
+
| Accessible name | Visible, non-empty **`FormField.Label`** describing the setting (for example, "Dark Mode"), not the state ("On"/"Off"). Use **`FormField.Label isHidden`** only when an equally clear visible alternative exists |
|
|
161
|
+
| Input wiring | **`FormField.Input as={Switch}`** inside **`FormField.Field`**. See [FormField accessibility](/components/inputs/form-field/#accessibility) for label, hint, error, and required wiring |
|
|
162
|
+
| Required state _(conditional)_ | `isRequired` on **`FormField`** only when the form cannot be submitted unless the Switch is on — native `required` on a checkbox means it must be checked |
|
|
163
|
+
| Disabled _(conditional)_ | `disabled` on **`FormField.Input`** when the spec marks the setting unavailable. See [Disabled](#disabled) |
|
|
164
|
+
| Programmatic focus _(conditional)_ | `ref` on **`FormField.Input`** and call `focus()` when the product requires it — omit by default (see **Programmatic focus** above and [Ref Forwarding](#ref-forwarding)) |
|
|
165
|
+
|
|
166
|
+
**Summary for code generation:**
|
|
167
|
+
|
|
168
|
+
- **REQUIRED:** **`FormField`** + visible **`FormField.Label`** + **`FormField.Input as={Switch}`**
|
|
169
|
+
inside **`FormField.Field`**
|
|
170
|
+
- **CONDITIONAL:** `isRequired` only when the Switch must be on; `disabled`; programmatic focus via
|
|
171
|
+
`ref`. See [FormField accessibility](/components/inputs/form-field/#accessibility) for shared
|
|
172
|
+
FormField conditionals (hint, error, and caution).
|
|
173
|
+
|
|
174
|
+
### Anti-Patterns
|
|
175
|
+
|
|
176
|
+
Do **not** generate code that does the following (see **Accessibility Requirements** above for what
|
|
177
|
+
to supply instead):
|
|
178
|
+
|
|
179
|
+
- Render **Switch** without **`FormField`** and **`FormField.Label`** — **Switch** has no built-in
|
|
180
|
+
label. For shared FormField anti-patterns (manual ARIA wiring, color-only errors, broken ID
|
|
181
|
+
references), see [FormField Anti-Patterns](/components/inputs/form-field/#anti-patterns)
|
|
182
|
+
- Manually set `role`, `aria-checked`, `aria-labelledby`, `aria-describedby`, `aria-invalid`, or
|
|
183
|
+
`id` on **Switch** — Canvas Kit wires these from the native checkbox and **`FormField`**
|
|
184
|
+
- Nest **`FormField`** inside **`FormField`** instead of using **`FormField.Field`** — the inner
|
|
185
|
+
**`FormField`** breaks the label association
|
|
186
|
+
- Put the state in the label (for example, "Dark Mode: On") or add a visually hidden "on"/"off"
|
|
187
|
+
string — the state is already announced from `role="switch"` and `checked`
|
|
188
|
+
- Set **`error`** directly on **Switch** inside **`FormField`** — set it on **`FormField`** so
|
|
189
|
+
`aria-invalid` and the visual ring stay in sync. Setting **`error`** on a Switch outside
|
|
190
|
+
**`FormField`** is visual only and does not set `aria-invalid`
|
|
191
|
+
- Use **`isRequired`** for a setting that can validly be off
|
|
192
|
+
- Use **Switch** for selections that only apply on form submission, or for multiple related
|
|
193
|
+
options — use [**Checkbox**](/components/inputs/checkbox/) instead
|
|
194
|
+
- Use **`aria-disabled`** instead of **`disabled`** — **Switch** maps unavailability to the native
|
|
195
|
+
**`disabled`** attribute
|
|
196
|
+
|
|
78
197
|
## Component API
|
|
79
198
|
|
|
80
199
|
<SymbolDoc name="Switch" fileName="/react/" />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-docs",
|
|
3
|
-
"version": "16.2.
|
|
3
|
+
"version": "16.2.3",
|
|
4
4
|
"description": "Documentation components of Canvas Kit components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"@stackblitz/sdk": "^1.11.0",
|
|
48
48
|
"@storybook/csf": "0.0.1",
|
|
49
49
|
"@workday/canvas-expressive-icons-web": "1.0.2",
|
|
50
|
-
"@workday/canvas-kit-labs-react": "^16.2.
|
|
51
|
-
"@workday/canvas-kit-preview-react": "^16.2.
|
|
52
|
-
"@workday/canvas-kit-react": "^16.2.
|
|
53
|
-
"@workday/canvas-kit-styling": "^16.2.
|
|
50
|
+
"@workday/canvas-kit-labs-react": "^16.2.3",
|
|
51
|
+
"@workday/canvas-kit-preview-react": "^16.2.3",
|
|
52
|
+
"@workday/canvas-kit-react": "^16.2.3",
|
|
53
|
+
"@workday/canvas-kit-styling": "^16.2.3",
|
|
54
54
|
"@workday/canvas-system-icons-web": "^5.0.3",
|
|
55
55
|
"@workday/canvas-tokens-web": "^4.4.0",
|
|
56
56
|
"markdown-to-jsx": "^7.2.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"mkdirp": "^1.0.3",
|
|
64
64
|
"typescript": "5.0"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "dd5a27ab062642ac115722808e063150f7866115"
|
|
67
67
|
}
|