Accessibility-flavored React components make your design system delicious!
— Kathleen McMahon
Frontend Engineer
O’Reilly Media
Slide 2
Topics covered
• Why use React
• Why accessible components?
• Design systems are a cookbook
• Design systems and React
• Icons
• Buttons
• Inputs
• Documentation
• Wrap-up
A design system is a collection of reusable components, guided by clear standards, that can be assembled together to build any number of applications.
Slide 16
Your Design system is a cookbook
Slide 17
Cookbooks have Personality
Slide 18
Design Systems and React
Slide 19
Slide 20
Slide 21
React is like a kitchen utensil
CC BY-SA 2.0: Jeppestown utensil
Slide 22
You are the cook
CC BY-SA 2.0: Jeppestown utensil
Slide 23
Components are your tried and true recipes
Slide 24
WCAG is Your reference material
Slide 25
Our cookbook is in beta
Slide 26
Component recipe
Slide 27
Start with high-quality ingredients (semantic HMTL)
Slide 28
Mix in key accessibility seasonings (ARIA … just a touch)
Slide 29
Follow the directions (documentation)
Slide 30
Provide helpful hints (best practices)
Slide 31
Icons
Slide 32
Icons Informative or decorative
• Informative icons need descriptive text
• Decorative icons need to be hidden from screen readers with the ‘aria-hidden’ attribute
Slide 33
Accessible Icon component: SVGs vs. Icon Fonts
Slide 34
Icon
• Icon font HTML pattern
Slide 35
Icon
• Apply the icon font as a pseudo-element
Slide 36
Icon
• Add descriptive icon text
Slide 37
Icon
• Wrap spans and convert display property to inline-block
Slide 38
Icon
• Screen reader hears: “\f12f email”
Slide 39
Icon
• Hide icon font from screen reader
Slide 40
Icon
• Visually-hide descriptive text from screen reader
Slide 41
Icon
• To hide, or not to hide?
Slide 42
Icon
• Hide a decorative icon from screen reader…
Slide 43
Icon
• Announce an informational icon to screen reader
Slide 44
React class component
Slide 45
React render function
Slide 46
Dear React, make the UI look like this.
Slide 47
JSX syntax
Slide 48
What this looks like in JavaScript
Slide 49
Mom’s Spaghetti
Slide 50
JSX syntax
Slide 51
class ⇒ className
close empty span
Slide 52
Renders as HTML in the browser
Slide 53
JSX syntax
Slide 54
Incoming props
Slide 55
Add component guardrails
Slide 56
IconHidden guardrails
Slide 57
Icon guardrails
Slide 58
Icon description guardrails
Slide 59
Helpful hints Informative Icon
Slide 60
Helpful hints Decorative icon
Slide 61
Helpful hints Custom-text informative Icon
Slide 62
Buttons
Slide 63
Buttons
• Buttons perform an action on the page
• Buttons should look and act like a button
• Use semantic HTML, get screen reader and keyboard functionality for free
Slide 64
Markup has meaning. There is no spec for “div: use it for whatever.”
— @scottohara at @boston_css
Slide 65
Button
<button class=”root”> Send an email </button>
Slide 66
Buttons
Slide 67
Slide 68
Button
Sprinkle some ARIA
Slide 69
Button
HTML syntax
Slide 70
JSX syntax
Slide 71
Add icon support
Slide 72
Wrap contents in span for flexbox
Slide 73
Allow for custom button text
Slide 74
Add click handler support
Add disabled button support
Slide 75
Add props support
Pop JSX into render ( )
Slide 76
No iconName? No icon rendered
Slide 77
Helpful hints Featured button
Slide 78
Helpful hints Featured Icon button
Slide 79
Helpful hints Featured button with custom Icon title
Slide 80
Inputs
Slide 81
Inputs - labels and error messages are key ingredients
• Labeled inputs give all users more context
Slide 82
Placeholders are NOT labels
• Avoid using placeholders instead of labels, users will lose context
• Hard to style across browsers
• Placeholders aren’t auto translated