-
Notifications
You must be signed in to change notification settings - Fork 152
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
Stepper accessibility fixes #4571
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: Accessibility | ||
redirect_from: | ||
- /components/stepper/accessibility/ | ||
--- | ||
|
||
## Accessibility | ||
|
||
The Stepper component has been designed with accessibility in mind. It can be used with keyboard navigation and includes properties that enhance the experience for users of assistive technologies. | ||
|
||
The following props provide additional information to screen readers, enhancing the accessibility of the respective component. By using them, you can ensure that users who rely on assistive technologies receive the necessary context and information about the component's purpose and functionality. | ||
|
||
- The `ariaLabel` prop allows you to specify an `aria-label` attribute of the component. | ||
|
||
- The `titleDecrement` prop allows you to specify an `aria-label` attribute for the decrement icon button in the Stepper (StepperStateless) component. | ||
|
||
- The `titleIncrement` prop allows you to specify an `aria-label` attribute for the increment icon button in the Stepper (StepperStateless) component. | ||
|
||
- The `ariaLabelledBy` prop allows you to specify an `aria-labelledby` attribute for the Stepper component. This attribute references the ID of the element that labels the Stepper, ensuring that screen readers announce the label correctly. | ||
|
||
Although these props are optional for the Stepper (StepperStateless) component itself, it is recommended to fill them in to ensure that the component can be perceived by assistive technologies. | ||
|
||
### Example | ||
|
||
```jsx | ||
<Stepper | ||
step={1} | ||
minValue={0} | ||
minValue={10} | ||
ariaLabel="Number of passengers" | ||
titleDecrement="Remove a passenger" | ||
titleIncrement="Add a passenger" | ||
/> | ||
``` | ||
|
||
The screen reader will announce the input title (`Number of passengers`) and buttons title (`Add a passenger`, `Remove a passenger`) once they are focused by the screen reader. | ||
|
||
```jsx | ||
<Stack> | ||
<Stack> | ||
<Text id="passengers">Passengers</Text> | ||
</Stack> | ||
<Stepper | ||
step={1} | ||
minValue={0} | ||
minValue={10} | ||
ariaLabel="Number of passengers" | ||
aria-labelledby="passengers" | ||
titleDecrement="Remove a passenger" | ||
titleIncrement="Add a passenger" | ||
/> | ||
</Stack> | ||
``` | ||
|
||
This example includes `ariaLabelledby` prop. In this case, `ariaLabelledBy` prop is prioritized over `ariaLabel`, so the screen reader will announce the input title (`Passengers`) and buttons title (`Add a passenger`, `Remove a passenger`) once they are focused by the screen reader. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,8 @@ const StepperStateless = ({ | |
titleDecrement, | ||
disabledIncrement, | ||
disabledDecrement, | ||
ariaLabel, | ||
ariaLabelledBy, | ||
}: Props) => { | ||
const theme = useTheme(); | ||
|
||
|
@@ -77,8 +79,8 @@ const StepperStateless = ({ | |
onDecrement(ev); | ||
} | ||
}} | ||
title={titleDecrement} | ||
icons={iconStyles} | ||
title={titleDecrement} | ||
/> | ||
<input | ||
className={cx( | ||
|
@@ -103,6 +105,8 @@ const StepperStateless = ({ | |
}} | ||
onBlur={onBlur} | ||
onFocus={onFocus} | ||
aria-label={ariaLabel} | ||
aria-labelledby={ariaLabelledBy} | ||
readOnly | ||
/> | ||
<ButtonPrimitive | ||
|
@@ -115,8 +119,8 @@ const StepperStateless = ({ | |
onIncrement(ev); | ||
} | ||
}} | ||
title={titleIncrement} | ||
icons={iconStyles} | ||
title={titleIncrement} | ||
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 was thinking of changing this prop name from I'm not sure if it makes sense to change this prop name, if it could be included within this PR or in a separate one. 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. So your suggestion is to keep prop names in Stepper as But anyway, I think it's out of scope and this should be tackled when making 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. No, that wouldn't make sense. :D My suggestion was to rename aria attribute in As you said, I also think it's out of the scope of this PR, that's the reason why I didn't touch ButtonPrimitive at all. |
||
/> | ||
</div> | ||
); | ||
|
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 would maybe add more elements to this example, as it probably wouldn't be placed in isolation but with some label? (This is based on the comment I put to the review with the image example, I just wanted to post it also here in case we add all these other props.)
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 added an example when using Stepper with a connected title (
ariaLabelledBy
prop is used).