Skip to content

Commit be42b0d

Browse files
committed
chore: update checkbox and label docs
1 parent 9bde625 commit be42b0d

File tree

2 files changed

+85
-114
lines changed

2 files changed

+85
-114
lines changed

packages/paste-website/src/pages/components/checkbox/index.mdx

Lines changed: 84 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,21 @@ export const getStaticProps = async () => {
5454

5555
## Guidelines
5656

57-
### Checkbox Group
57+
### About Checkbox Group
5858

59-
<Paragraph>{meta.description}</Paragraph>
59+
Use Checkbox Groups when you have multiple binary choices to make but all choices belong to a single group or field. Example: Choosing capabilities when searching for a phone number to provision from Twilio. By placing them in a group, users should be able to clearly understand which options make up the collection and how those options are related to each other.
6060

61-
Checkbox groups are used when you have multiple binary choices to make but all choices belong to a single group or field. For example, choosing capabilities when searching for a Phone Number to provision from Twilio. By placing them in a group, users should be able to clearly understand which options make up the collection and also how those options are related to each other.
61+
For guidance on using a Checkbox in a form, refer to our [Form pattern](/patterns/form) guidelines.
62+
63+
### About Checkbox
64+
65+
Use a checkbox to present a user with a binary (e.g. on/off) choice that is part of a form. A checkbox should not be used to apply a user's choice instantly. In that case, such as enabling a system feature, use the [Switch component](/components/switch).
6266

6367
#### Accessibility
6468

65-
- Checkbox groups **must** have a group legend that describes the collection.
66-
- The label _should_ be visible.
67-
- The label may be visually hidden or provided via `aria-label` on the group component if the entire form is just a single checkbox group with no other form elements. The grouping should be visually implicit, but a description still needs to be provided for assistive technology.
69+
- Checkbox Group must have a group legend that describes the collection. The label should be visible. However if the entire form is just a single checkbox group with no other form elements, it may be visually hidden or provided via `aria-label` on the group component. The grouping should be visually implicit, but a description still needs to be provided for assistive technology.
70+
- Checkbox must have a visible label.
71+
- When displaying additional content based on checking a checkbox, be sure that the new content appears after the checkbox so that it is naturally discoverable by assistive technology users.
6872

6973
### Checkbox
7074

@@ -81,23 +85,23 @@ Use a checkbox to present a user with a binary (e.g. on/off) choice that is part
8185

8286
## Controlled vs. uncontrolled checkboxes
8387

84-
The checkbox can either be controlled, meaning there is an external state that determines if the checkbox is checked or not, or uncontrolled, meaning the checkbox manages its own state.
88+
Checkbox can either be controlled, meaning there is an external state that determines if the checkbox is checked or not, or uncontrolled, meaning the checkbox manages its own state.
8589

86-
To make an uncontrolled checkbox, you do not pass the `checked` or `onChange` props. If you need the checkbox to be checked by default, use the `defaultChecked` prop.
90+
To make an uncontrolled checkbox, do not pass the `checked` or `onChange` props. If you need the checkbox to be checked by default, use the `defaultChecked` prop.
8791

8892
<LivePreview scope={{Checkbox}} noInline>
8993
{uncontrolledCheckbox}
9094
</LivePreview>
9195

92-
To make a controlled checkbox, you must pass the `checked` and `onChange` props. You cannot use the `defaultChecked` prop in a controlled checkbox.
96+
To make a controlled checkbox, pass the `checked` and `onChange` props. You cannot use the `defaultChecked` prop in a controlled checkbox.
9397

9498
<LivePreview scope={{Checkbox}} noInline>
9599
{controlledCheckbox}
96100
</LivePreview>
97101

98-
## Examples
102+
## Checkbox examples
99103

100-
### Basic checkbox with label
104+
### Basic Checkbox with Label
101105

102106
A checkbox is always displayed next to a visible label.
103107

@@ -107,8 +111,7 @@ A checkbox is always displayed next to a visible label.
107111

108112
### Checkbox with help text
109113

110-
In cases where the checkbox requires additional context, you can display this information as help text below the checkbox control and label. This can help keep checkbox labels concise. In order to maintain styling consistency, be sure to use the `helpText` prop here instead of using the Help Text component.
111-
114+
Use Checkbox with Help Text in cases where the checkbox requires additional context. In order to maintain styling consistency, be sure to use the `helpText` prop here instead of using the Help Text component.
112115
<LivePreview scope={{Checkbox}} language="jsx">
113116
{`<Checkbox id="enabled" value="enabled" name="enabled" helpText="Determines if certificate validation is performed on all Twilio originated requests">
114117
Enable SSL certificate validation
@@ -117,17 +120,29 @@ In cases where the checkbox requires additional context, you can display this in
117120

118121
### Required checkbox
119122

120-
When a checkbox is required to be checked, a required indicator should be displayed alongside the label. The label text should also be written in such a way that this requirement is clear to the user.
123+
Use the `required` prop to show a required indicator alongside the label when a checkbox is required to be checked. Ensure the label text includes wording that successfully describes the requirement to the user that they should check the box.
121124

122125
<LivePreview scope={{Checkbox}} language="jsx">
123126
{`<Checkbox id="delete" value="delete" name="delete" required>
124127
Confirm this message should be deleted
125128
</Checkbox>`}
126129
</LivePreview>
127130

131+
### Checkbox with suffix
132+
133+
You can provide additional information about an individual item by adding a non-string element as a suffix. The suffix can be any non-string element that is not interactive.
134+
135+
<LivePreview scope={{Checkbox, Badge, Box}} language="jsx">
136+
{`<Checkbox id="busy" value="busy" name="busy">
137+
<Box display="flex" columnGap="space30">Busy <Badge variant="new" size="small">New</Badge></Box>
138+
</Checkbox>`}
139+
</LivePreview>
140+
141+
## Checkbox Group examples
142+
128143
### Basic checkbox group
129144

130-
Multiple checkboxes and their labels are grouped together with a common group component. The group legend must be the first element inside the group. It must appear before any checkboxes or other content.
145+
Group related checkboxes using a common group component. The group legend should come first to clearly describe the set of options.
131146

132147
<LivePreview scope={{Checkbox, CheckboxGroup}} language="jsx">
133148
{`<CheckboxGroup
@@ -145,7 +160,7 @@ Multiple checkboxes and their labels are grouped together with a common group co
145160

146161
### Checkbox group with help text
147162

148-
You can provide additional information about the group with the use of help text. Help text can appear after the group label but before the first group member. Each item in the group may also provide their own, individual help text.
163+
Use help text to give more context about a Checkbox group. In order to maintain styling consistency, be sure to use the helpText prop here instead of using the Help Text component. Individual checkboxes can also include their own help text if needed.
149164

150165
<LivePreview scope={{Checkbox, CheckboxGroup, Anchor, Text}} language="jsx">
151166
{`<CheckboxGroup
@@ -178,33 +193,51 @@ You can provide additional information about the group with the use of help text
178193
</CheckboxGroup>`}
179194
</LivePreview>
180195

181-
### Checkbox with suffix
196+
### Required Checkbox Group
182197

183-
You can provide additional information about an individual item by adding a non-string element as a suffix. The suffix can be any non-string element that is not interactive.
198+
Use a required indicator alongside the label when at least one item from the Checkbox Group is required to be checked.
184199

185-
<LivePreview scope={{Checkbox, CheckboxGroup, Badge, Box}} language="jsx">
200+
<LivePreview scope={{Checkbox, CheckboxGroup}} language="jsx">
186201
{`<CheckboxGroup
187-
name="call logs status"
188-
legend="Call logs status"
189-
helpText="Select at least 1 status to view results"
202+
name="desktop"
203+
legend="Select the clients you would like to test."
204+
required
190205
>
191-
<Checkbox id="busy" value="busy">
192-
<Box display="flex" columnGap="space30">Busy <Badge variant="new" size="small">New</Badge></Box>
206+
<Checkbox id="apple_mail" value="apple_mail">
207+
Apple Mail
193208
</Checkbox>
194-
<Checkbox id="canceled" value="canceled">
195-
Canceled
209+
<Checkbox id="outlook" value="outlook">
210+
Outlook
196211
</Checkbox>
197-
<Checkbox id="completed" value="completed">
198-
Completed
212+
</CheckboxGroup>`}
213+
</LivePreview>
214+
215+
### Horizontal Checkbox Group
216+
217+
Use a horizontal layout for Checkbox Group when options can be placed next to each other in a logical order and the labels for each option are shorter than 3 words.
218+
219+
<LivePreview scope={{Checkbox, CheckboxGroup, Badge, Box}} language="jsx">
220+
{`<CheckboxGroup
221+
name="select number type"
222+
legend="Select number type"
223+
orientation="horizontal"
224+
>
225+
<Checkbox id="local" value="local">
226+
<Box display="flex" columnGap="space30">Local</Box>
199227
</Checkbox>
200-
<Checkbox id="queued" value="queued">
201-
Queued
228+
<Checkbox id="mobile" value="mobile">
229+
Mobile
230+
</Checkbox>
231+
<Checkbox id="toll-free" value="toll-free">
232+
Toll-free
202233
</Checkbox>
203234
</CheckboxGroup>`}
204235
</LivePreview>
205236

206237
### Checkbox Disclaimer
207238

239+
Use Checkbox Disclaimer if a user needs to agree to Terms of Service or something similar.
240+
208241
<LivePreview scope={{CheckboxDisclaimer, Text}} language="jsx">
209242
{`<CheckboxDisclaimer id="disclaimer" value="disclaimer" name="disclaimer">
210243
I declare the information provided above is accurate. I acknowledge that Twilio will process the information provided above for the purpose of identity verification, and will be sharing it with my local telecomm providers or authorities where required by local law. I understand that Twilio phone numbers may be taken out of service for inaccurate or false information.
@@ -213,8 +246,7 @@ You can provide additional information about an individual item by adding a non-
213246

214247
### Internationalization
215248

216-
To internationalize a checkbox, simply pass different text to the checkbox and checkbox group. The only exception to this is the required dot in the legend of a required checkbox group. To change the required dot's text, use the `i18nRequiredLabel` prop.
217-
249+
To internationalize a checkbox, pass different text to Checkbox and Checkbox Group. The only exception to this is the required dot in the legend of a required Checkbox Group. To change the required dot's text, use the `i18nRequiredLabel` prop.
218250
<LivePreview scope={{Checkbox, CheckboxGroup}} language="jsx">
219251
{`<CheckboxGroup
220252
name="days"
@@ -244,17 +276,17 @@ To internationalize a checkbox, simply pass different text to the checkbox and c
244276

245277
### Unchecked, checked and indeterminate
246278

247-
The default state of a checkbox indicates that the control is unchecked, or not selected. When a checkbox is clicked or the spacebar is pressed when focused, the checkbox will become checked. Doing so again will place the checkbox back into the unchecked state. A checkbox can be placed into a pre-checked state by setting the `checked` property.
279+
By default, checkboxes are unchecked. Clicking or pressing the spacebar toggles the checked state on or off. You can set a checkbox to be pre-checked using the `checked` property.
248280

249-
The third state a checkbox can appear in is the indeterminate state. This is to indicate that a checkbox is neither checked nor unchecked. This is useful when dealing with related groups of checkboxes that have a dependent relationship, for example, a select all feature.
281+
Checkboxes also support an indeterminate state, used when the checkbox is neither fully checked nor unchecked—like in a “Select all” scenario where only some items are selected.
250282

251283
<LivePreview scope={{Checkbox, CheckboxGroup}} noInline>
252284
{indeterminateExample}
253285
</LivePreview>
254286

255-
### Disabled checkbox
287+
### Disabled Checkbox
256288

257-
Use a disabled checkbox to indicate that a particular option cannot be interacted with or can be safely ignored.
289+
Use a disabled Checkbox to indicate that a particular option cannot be interacted with or can be safely ignored.
258290

259291
<LivePreview scope={{Checkbox}} language="jsx">
260292
{`<Checkbox
@@ -268,55 +300,30 @@ Use a disabled checkbox to indicate that a particular option cannot be interacte
268300
</Checkbox>`}
269301
</LivePreview>
270302

271-
### Required checkbox group
272-
273-
When at least one item from the checkbox group is required, a required indicator should be displayed alongside the group legend. The group help text should be used to describe the requirement.
274-
275-
<LivePreview scope={{Checkbox, CheckboxGroup}} language="jsx">
276-
{`<CheckboxGroup
277-
name="email"
278-
legend="Email Notifications"
279-
helpText="We can remind you when one of your Buffer is looking a little empty."
280-
required
281-
>
282-
<Checkbox id="empty_buffer" value="empty_buffer">
283-
Empty buffer
284-
</Checkbox>
285-
<Checkbox id="newsletter" value="newsletter">
286-
Newsletter
287-
</Checkbox>
288-
<Checkbox id="update_failures" value="update_failures">
289-
Update failures
290-
</Checkbox>
291-
</CheckboxGroup>`}
292-
</LivePreview>
293-
294-
### Disabled checkbox group
303+
### Disabled Checkbox Group
295304

296305
Use a disabled checkbox group to indicate that all options cannot be interacted with, with each checkbox individually disabled.
297306

298307
<LivePreview scope={{Checkbox, CheckboxGroup}} language="jsx">
299308
{`<CheckboxGroup
300-
name="capabilities"
301-
legend="Capabilities"
302-
orientation="horizontal"
309+
name="desktop"
310+
legend="Select the clients you would like to test."
303311
disabled
304312
>
305-
<Checkbox id="voice" value="voice">
306-
Voice
307-
</Checkbox>
308-
<Checkbox id="fax" value="fax">
309-
Fax
313+
<Checkbox id="apple_mail" value="apple_mail">
314+
Apple Mail
310315
</Checkbox>
311-
<Checkbox id="sms" value="sms">
312-
SMS
316+
<Checkbox id="outlook" value="outlook">
317+
Outlook
313318
</Checkbox>
314319
</CheckboxGroup>`}
315320
</LivePreview>
316321

317-
### Checkbox group with an inline error
322+
### Checkbox group with an error
318323

319-
If the selected options don't pass the group validation requirements, display an inline error message below the checkbox group.
324+
If the selected options don't pass the group validation requirements, use the `errorText` prop to show an error message.
325+
326+
Focus the error text on how users can fix the issue. For additional guidance on how to compose error messages, refer to the [Error state pattern](/patterns/error-state).
320327

321328
<LivePreview scope={{Checkbox, CheckboxGroup}} language="jsx">
322329
{`<CheckboxGroup
@@ -339,23 +346,19 @@ If the selected options don't pass the group validation requirements, display an
339346

340347
Checkboxes and Checkbox Groups must have a visible label.
341348

342-
- Aim for no more than 3 words. If the label must be longer and space is limited, wrap the label.
349+
- Aim for no more than 3 words.
343350
- Structure each checkbox label similarly. For example, make each checkbox a noun.
344351
- Avoid articles ("a", "the") and punctuation. For example, use "SIM registration code" rather than "The SIM registration code".
345352

346-
Checkbox labels should reflect what happens if the box is checked. Avoid situations where the user must check a box to negate something. For example, "Don't send message."
347-
348-
Avoid constructing the legend and label text to read as a sentence.
353+
Checkbox labels should reflect what happens if the box is checked. Avoid situations where the user must check a box to negate something. For example, "Don't send messages."
349354

350-
Use [Help Text](/components/help-text) to give additional context and provide enough information to avoid errors. Consider using Help Text to indicate to users that they can select multiple options. Limit Help Text to 1-2 sentences.
355+
Use the `helpText` prop to give additional context and provide enough information to avoid errors. Consider using help text to indicate to users that they can select multiple options. Limit help text to 1-2 sentences.
351356

352357
To support internationalization, avoid starting a sentence with the legend and using the field to finish it since sentence structures vary across languages. For example, use "Phone Number capabilities", not "Phone Number capabilities include:".
353358

354-
### Validation and errors
359+
### Validation
355360

356-
Validate form fields on form submission. Don't validate each item in a group, treat validation on the group as a whole.
357-
358-
Use inline error text to explain how to fix an error. Because space is typically limited, focus the error text on how users can fix the issue. For additional guidance on how to compose error messages, refer to the [error state pattern](/patterns/error-state).
361+
Validate a checkbox or a checkbox group on form submission. Don't validate each item in a group, treat validation on the group as a whole. For additional guidance on how to validate form fields, refer to our [Form pattern validation](/patterns/form#validation) guidelines.
359362

360363
## Do and don't
361364

@@ -372,22 +375,6 @@ Use inline error text to explain how to fix an error. Because space is typically
372375
<Dont title="Don't" body="Don't save or persist a user's choice upon checking a checkbox." />
373376
</DoDont>
374377

375-
<DoDont>
376-
<Do
377-
title="Do"
378-
body="Keep help text and error text concise and simple. If you need to use more than 2 sentences to explain a field, link out to supporting docs or trigger a popover instead."
379-
/>
380-
<Dont title="Don't" body="Don't use more than 2 sentences in help text or error text." />
381-
</DoDont>
382-
383-
<DoDont>
384-
<Do
385-
title="Do"
386-
body="Include a visible label on every checkbox. Include a visible legend for the entire group of checkboxes."
387-
/>
388-
<Dont title="Don't" body="Don't leave floating, unlabelled checkboxes." />
389-
</DoDont>
390-
391378
<DoDont>
392379
<Do title="Do" body="Write label text that clearly describes the value being requested." />
393380
<Dont title="Don't" body="Don't use the legend and label text in a way that is intended to be read as a sentence." />
@@ -397,19 +384,3 @@ Use inline error text to explain how to fix an error. Because space is typically
397384
<Do title="Do" body="Write legend text to describe a group and their intended relationship together." />
398385
<Dont title="Don't" body="Don't use a legend as a heading or section title." />
399386
</DoDont>
400-
401-
<DoDont>
402-
<Do title="Do" body="Provide actionable error text explaining how to fix the error." />
403-
<Dont title="Don't" body="Don't display system messages as error text or only what field errored." />
404-
</DoDont>
405-
406-
<DoDont>
407-
<Do
408-
title="Do"
409-
body="Use error text to explain how to resolve the error. For example, 'Accept the terms of agreement.'"
410-
/>
411-
<Dont
412-
title="Don't"
413-
body="Don’t focus on whether the field is required. For example, 'Accepting the terms of agreement is required.'"
414-
/>
415-
</DoDont>

packages/paste-website/src/pages/components/label/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Use `optional` prop to show users which fields are optional to fill out.
181181

182182
### Disabled Label
183183

184-
Use the disabled prop if a the label is associated with a disabled form field to show users that they can't interact with the field.
184+
Use the disabled prop if the label is associated with a disabled form field to show users that they can't interact with the field.
185185

186186
<LivePreview scope={{Input, Label, HelpText}} language="jsx">
187187
{`<>

0 commit comments

Comments
 (0)