-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Button and link a11y docs #924
Changes from 44 commits
9c9f783
39d1b54
ecce3ec
b9f38f2
1238cfe
ca9e383
016c57d
6ccae15
85d1c9a
0eb1e78
5da2eae
48f099f
af046ce
e4bf84c
ca42994
be04b96
de37a49
110e6dd
5d9fab9
e08834b
b59337c
94210c3
f4c5bde
d7beb60
2308160
1e04789
3e52023
f61415b
2690df4
25feebc
6375184
ee89b26
3670720
c60a031
2779012
cda1178
c20f01b
a664e02
d27cdfe
3b9f974
ebe8ddb
023c599
ece28ed
f5ff638
f0c7e43
1b536bb
5a70def
6ce31b7
b602322
e4f56cd
b75ec5c
39c31e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ keywords: | |
|
||
# Button | ||
|
||
Buttons are used to make common actions immediately visible and easy to perform with one click or tap. Merchants can use it to navigate, or take action. | ||
Buttons are used to make common actions immediately visible and easy to perform with one click, tap, or keypress. Merchants can use them to navigate or to take action. | ||
dpersing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
--- | ||
|
||
|
@@ -289,3 +289,130 @@ Use when a button has been pressed and the associated action is in progress. | |
|
||
- To learn how to combine or lay out multiple buttons, [use the button group component](/components/actions/button-group) | ||
- To embed an action into a line of text, [use the link component](/components/navigation/link) | ||
|
||
--- | ||
|
||
## Accessibility | ||
dpersing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<!-- content-for: android --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS and Android content for the button page, since there are separate tabs. We don't currently have native-specific guidance so I've linked to the platform best practices. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although it's a bit awkward from the "Web" perspective to begin the section with external resources that don't apply to web, my understanding is that this will eventually change, when we have native-specific guidance. To make it more clear what content applies to the reader:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sadiesaurus The sections here display on the web, iOS, and Android tabs in the UI in the style guide, which is what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhhh, yes now I see. I didn't 🎩 it properly last time. This works well! Please disregard my comment! 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that headings would help with the Markdown readability in GitHub itself. I couldn't find a solid and elegant way to make it work :/ @BPScott and I might have cycles to look into it later this year. |
||
|
||
See Material Design and development documentation about accessibility for Android: | ||
|
||
- [Accessible design on Android](https://material.io/design/usability/accessibility.html) | ||
- [Accessible development on Android](https://developer.android.com/guide/topics/ui/accessibility/) | ||
|
||
<!-- /content-for --> | ||
|
||
<!-- content-for: ios --> | ||
|
||
See Apple’s Human Interface Guidelines and API documentation about accessibility for iOS: | ||
|
||
- [Accessible design on iOS](https://developer.apple.com/design/human-interface-guidelines/ios/app-architecture/accessibility/) | ||
- [Accessible development on iOS](https://developer.apple.com/accessibility/ios/) | ||
|
||
<!-- /content-for --> | ||
|
||
<!-- content-for: web --> | ||
|
||
### Structure | ||
|
||
Buttons can have different states that are visually and programmatically conveyed to merchants. | ||
|
||
- Use the `ariaControls` prop to add an `aria-controls` attribute to the button. Use the attribute to point to the unique `id` of the content that the button manages. | ||
- If a button expands or collapses adjacent content, then use the `ariaExpanded` prop to add the `aria-expanded` attribute to the button. Set the value to convey the current expanded (`true`) or collapsed (`false`) state of the content. | ||
- Use the `disabled` prop to set the `disabled` state of the button. This prevents merchants from being able to interact with the button, and conveys its inactive state to assistive technologies. | ||
|
||
#### Navigation | ||
|
||
Merchants generally expect buttons to submit data or take action, and for links to navigate. If navigation is required for the button component, use the `url` prop. The control will output an anchor styled as a button, instead of a button in HTML, to help convey this difference. | ||
|
||
For more information on making accessible links, see the [link component](/components/navigation/link). | ||
|
||
### Labeling | ||
|
||
The `accessibilityLabel` prop adds an `aria-label` attribute to the button, which can be accessed by assistive technologies like screen readers. Typically, this label text replaces the visible text on the button for merchants who use assistive technology. | ||
|
||
Use `accessibilityLabel` for a button if: | ||
|
||
- The button’s visible text doesn’t adequately convey the purpose of the button to non-visual merchants | ||
- The button has no text and relies on an icon alone to convey its purpose | ||
|
||
To help support merchants who use speech activation software as well as sighted screen reader users, make sure that the `aria-label` text includes any button text that’s visible. Mismatches between visible and programmatic labeling can cause confusion, and might prevent voice recognition commands from working. | ||
|
||
When possible, give the button visible text that clearly conveys its purpose without the use of `accessibilityLabel`. When no additional content is needed, duplicating the button text with `accessibilityLabel` isn’t necessary. | ||
|
||
<!-- usageblock --> | ||
|
||
#### Do | ||
|
||
```jsx | ||
<Button>Edit shipping address</Button> | ||
``` | ||
|
||
```jsx | ||
<Heading>Shipping address</Heading> | ||
<Button accessibilityLabel="Edit shipping address">Edit</Button> | ||
``` | ||
|
||
#### Don’t | ||
|
||
```jsx | ||
<Button accessibilityLabel="Change your shipping address">Edit</Button> | ||
``` | ||
|
||
```jsx | ||
<Button accessibilityLabel="Edit">Edit</Button> | ||
``` | ||
|
||
<!-- end --> | ||
|
||
#### External links | ||
|
||
When you use the button component to create a link to an external resource: | ||
|
||
- Use the `external` prop to make the link open in a new tab (or window, depending on the merchant’s browser settings) | ||
- Use the `icon` prop to add the `external` icon to the button | ||
- Use the `accessibilityLabel` prop to include the warning about opening a new tab in the button text for non-visual screen reader users | ||
|
||
For more information on making accessible links, see the [link component](/components/navigation/link). | ||
|
||
<!-- usageblock --> | ||
|
||
#### Do | ||
|
||
```jsx | ||
<Button | ||
accessibilityLabel="Terms and conditions (opens a new window)" | ||
icon="external" | ||
url="http://example.com" | ||
external | ||
> | ||
Terms and conditions | ||
</Button> | ||
``` | ||
|
||
#### Don’t | ||
|
||
```jsx | ||
<Button url="http://example.com" external>Terms and conditions</Button> | ||
<Button url="http://example.com" external> | ||
Terms and conditions | ||
</Button> | ||
``` | ||
|
||
<!-- end --> | ||
|
||
### Keyboard support | ||
|
||
Buttons use browser defaults for keyboard interactions. | ||
|
||
- Give buttons keyboard focus with the <kbd>tab</kbd> key (or <kbd>shift</kbd> + <kbd>tab</kbd> when tabbing backwards) | ||
- Activate buttons with the <kbd>enter</kbd>/<kbd>return</kbd> key or the <kbd>space</kbd> key | ||
|
||
#### Custom key events | ||
|
||
Use the `onKeyDown`, `onKeyPress`, and `onKeyUp` props to create custom events for buttons. With these props, you can use buttons to create complex, custom interactions like drag-and-drop interfaces. | ||
|
||
Since these props introduce non-standard features to buttons, make sure to include accessible instructions so that merchants can understand how to use these features. | ||
|
||
<!-- /content-for --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused as to why some of these unrelated entries are in this PR?