Skip to content

Commit e56e83d

Browse files
committed
feat: add accessiblity parts for button
1 parent a46df38 commit e56e83d

File tree

2 files changed

+92
-31
lines changed

2 files changed

+92
-31
lines changed

content/en/docs/forms/button.mdx

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ end
213213
<button type="button" class="button-lg">Large</button>
214214

215215
<!-- Icon-only Button -->
216-
<button type="button" class="button-icon" aria-label="Settings">
217-
<svg class="icon" aria-hidden="true">
216+
<button type="button" aria-label="Settings">
217+
<svg aria-hidden="true">
218218
<use href="#icon-settings" />
219219
</svg>
220220
</button>
@@ -234,57 +234,96 @@ end
234234
</form>
235235
```
236236

237-
## Browser Support
237+
## Accessibility
238238

239-
<BrowserSupport features={["html.elements.button", "api.HTMLButtonElement"]} />
239+
### ARIA Attributes
240+
241+
**Required ARIA attributes:**
242+
243+
- Use `aria-label` for icon-only buttons
244+
- Use `aria-pressed` for toggle buttons
245+
- Use `aria-expanded` for buttons that control expandable content
246+
- Use `aria-disabled="true"` instead of the `disabled` attribute
247+
- Use `aria-describedby` to associate additional descriptive text
248+
249+
### Screen Reader Support
250+
251+
**Implementation example:**
252+
253+
```html
254+
<!-- Icon-only button with proper ARIA -->
255+
<button type="button" aria-label="Close dialog">
256+
<svg aria-hidden="true">
257+
<use href="#icon-close" />
258+
</svg>
259+
</button>
260+
261+
<!-- Toggle button with ARIA pressed state -->
262+
<button type="button" aria-pressed="false"">
263+
<span>Dark mode</span>
264+
</button>
265+
266+
<!-- Expandable content button -->
267+
<button type="button" aria-expanded="false" aria-controls="content-1">
268+
<span>Show more</span>
269+
</button>
270+
```
271+
272+
### Keyboard Navigation
273+
274+
- Buttons must be focusable and activated with both Enter and Space keys
275+
- Focus order should follow a logical sequence
276+
- Focus states must be clearly visible
277+
- Avoid removing focus outlines without providing alternatives
278+
- Maintain focus after interactions (e.g., after closing a modal)
240279
241280
## Testing Guidelines
242281
243282
### Functional Testing
244283
245284
**Should ✓**
246285
247-
- Show a loader when the button is submitting a form
248-
- Disable the button during form submission to prevent double submissions
249-
- Handle click events and trigger the appropriate action
250-
- Maintain proper visual states (hover, focus, active, disabled)
251-
- Support keyboard interaction (Enter and Space keys)
252-
- Preserve button width when switching between normal and loading states
253-
- Reset to initial state after operation completion
286+
- [ ] Show a loader when the button is submitting a form
287+
- [ ] Disable the button during form submission to prevent double submissions
288+
- [ ] Handle click events and trigger the appropriate action
289+
- [ ] Maintain proper visual states (hover, focus, active, disabled)
290+
- [ ] Support keyboard interaction (Enter and Space keys)
291+
- [ ] Preserve button width when switching between normal and loading states
292+
- [ ] Reset to initial state after operation completion
254293
255294
### Accessibility Testing
256295
257296
**Should ✓**
258297
259-
- Be focusable and have visible focus indicators
260-
- Have proper ARIA labels, especially for icon-only buttons
261-
- Maintain sufficient color contrast ratios (WCAG 2.1 AA)
262-
- Support screen reader announcements of button state changes
263-
- Be operable with keyboard navigation
264-
- Communicate loading states to assistive technologies
265-
- Have appropriate touch target sizes (minimum 44x44px)
298+
- [ ] Be focusable and have visible focus indicators
299+
- [ ] Have proper ARIA labels, especially for icon-only buttons
300+
- [ ] Maintain sufficient color contrast ratios (WCAG 2.1 AA)
301+
- [ ] Support screen reader announcements of button state changes
302+
- [ ] Be operable with keyboard navigation
303+
- [ ] Communicate loading states to assistive technologies
304+
- [ ] Have appropriate touch target sizes (minimum 44x44px)
266305
267306
### Visual Testing
268307
269308
**Should ✓**
270309
271-
- Maintain consistent styling across different variants (primary, secondary, destructive)
272-
- Display icons with correct alignment and spacing
273-
- Show proper visual feedback for all interactive states
274-
- Render correctly across different viewport sizes
275-
- Handle text overflow appropriately
276-
- Display loading spinners centered within the button
277-
- Maintain proper padding and margins in all states
310+
- [ ] Maintain consistent styling across different variants (primary, secondary, destructive)
311+
- [ ] Display icons with correct alignment and spacing
312+
- [ ] Show proper visual feedback for all interactive states
313+
- [ ] Render correctly across different viewport sizes
314+
- [ ] Handle text overflow appropriately
315+
- [ ] Display loading spinners centered within the button
316+
- [ ] Maintain proper padding and margins in all states
278317
279318
### Performance Testing
280319
281320
**Should ✓**
282321
283-
- Render without layout shifts
284-
- Handle rapid click events appropriately
285-
- Maintain smooth transitions between states
286-
- Load icons and spinners efficiently
287-
- Function without JavaScript (progressive enhancement)
322+
- [ ] Render without layout shifts
323+
- [ ] Handle rapid click events appropriately
324+
- [ ] Maintain smooth transitions between states
325+
- [ ] Load icons and spinners efficiently
326+
- [ ] Function without JavaScript (progressive enhancement)
288327
289328
### Testing Tools
290329
@@ -294,6 +333,10 @@ end
294333
- Visual Regression: [Percy](https://percy.io/) or [Chromatic](https://www.chromatic.com/)
295334
- Cross-browser: [BrowserStack](https://www.browserstack.com/) or [Sauce Labs](https://saucelabs.com/)
296335
336+
## Browser Support
337+
338+
<BrowserSupport features={["html.elements.button", "api.HTMLButtonElement"]} />
339+
297340
## Design Tokens
298341
299342
These design tokens follow the [Design Tokens Format](https://design-tokens.github.io/community-group/format/) specification and can be used with various token transformation tools to generate platform-specific variables.
@@ -411,7 +454,7 @@ These design tokens follow the [Design Tokens Format](https://design-tokens.gith
411454
### Articles
412455
413456
- [button: The Button element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button)
414-
- [Ive been doing buttons wrong! Have you?](https://uxplanet.org/ive-been-doing-buttons-wrong-have-you-2117c0066613) by Adham Dannaway
457+
- [I've been doing buttons wrong! Have you?](https://uxplanet.org/ive-been-doing-buttons-wrong-have-you-2117c0066613) by Adham Dannaway
415458
- [A comprehensive guide to buttons](https://uxplanet.org/a-comprehensive-guide-to-buttons-8f3b8a1c6f0d) by UX Planet
416459
- [A comprehensive guide to designing UX buttons](https://www.invisionapp.com/inside-design/comprehensive-guide-designing-ux-buttons/?ref=checklist.design) by InVision
417460

templates/docs/component.mdx.hbs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ end
9595
```html
9696
<!-- Basic implementation example -->
9797
```
98+
## Accessibility
99+
100+
### ARIA Attributes
101+
102+
**Required ARIA attributes:**
103+
- [Required ARIA attribute 1]
104+
- [Required ARIA attribute 2]
105+
106+
### Screen Reader Support
107+
108+
**Implementation example:**
109+
```html
110+
<!-- Basic implementation example -->
111+
```
98112

99113
## SEO
100114

@@ -110,6 +124,10 @@ end
110124
- [Test case 1]
111125
- [Test case 2]
112126

127+
## Browser Support
128+
129+
<BrowserSupport features={[]} />
130+
113131
## Design Tokens
114132

115133
These design tokens follow the [Design Tokens Format](https://design-tokens.github.io/community-group/format/) specification and can be used with various token transformation tools to generate platform-specific variables.

0 commit comments

Comments
 (0)