Skip to content
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

Slider accessibility #320

Merged
merged 7 commits into from
Feb 17, 2023

Conversation

mauromascarenhas
Copy link

@mauromascarenhas mauromascarenhas commented Dec 10, 2022

Proposed changes

Enhanced accessibility performance of Materialize's Slider component by adding proper ARIA attributes and better support to keyboard navigation.

Following W3C's accessible carousel example, some new accessibility features have been implemented:

  • Pause transition on mouve hover: It is possible to disable this default behaviour by setting "pauseOnHover" option to "false";
  • Pause transition on focus (generally triggered by keyboard navigation): It is possible to disable this default behaviour by setting "pauseOnFocus" option to "false";
  • Indicators are now focusable by default, since they are no longer simple list items, but buttons instead.
  • Indicator text label (only detected by assistive technologies): It is possible to change the default label by setting a proper function in "indicatorLabelFunc" option;
  • "Aria-controls" attribute to indicators/buttons;
  • Slides are now automatically focused when its corresponding indicator has been selected;
  • "Hidden" slides can no longer receive keyboard focus and are hidden to assistive technologies.

In the advent of the implementation of those new features, some "side features" had to be implemented:

  • Every slider must have a proper id, so, indicators are able to reference them. Therefore a new id will be assigned to the slider element on initialization if it does not have one yet.
  • A new "eventPause" prop indicating whether the slider is paused by user interation or not has been added.¹

¹ It is important to take notice that calling slider.pause() by code has precedence over pauses caused by events. Thus, the slider will not resume when mouse leaves the slider or when focus is lost.

NB: There are other aspects of an "accessible slider" covered by W3C example which were not implemented here due to lack of escope (e.g.: Our current implementation does not provides a play/pause button per spec.).

PS.: Since this component did not have any test implementation, a new complete set of test files have also been implemented 😄.

Screenshots (if appropriate) or codepen:

Video

Slider.Accessibility.sample.mp4

Screen capture video of Firefox browser displaying a sample slider. It is paused on mouse hover and on focus. It also sets focus to its respective slide when a indicator is selected².

² Focus style has been set for demo purposes.

Image

Screenshot of Firefox browser displaying a Slider sample and its respective accessibility properties

Slider accessibility properties.

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to change).

Checklist:

  • I have read the CONTRIBUTING document.
  • My commit messages follows the conventional commit format
  • My change requires a change to the documentation, and updated it accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Improve slider support to assistive technologies (e.g.: screen readers):

- Add "pause" options to slider initialization:
    - pauseOnFocus: Slider should pause when receive keyboard focus;
    - pauseOnHover: Slider should pause when hovered by mouse;
- New "indicatorLabelFunc": Must generate ARIA labels for indicators;
- New eventPause prop: is true if slider is paused by focus/hover event;
- Slider must receive id if does not have one;
- Sliders are able to receive focus by code;
- Non-current slides are also hidden in CSS (also from screen readers);
- Add button to indicators:
    - Update CSS;
    - Update event handlers.
- Indicator click should focus current slide.
Implement slider tests:

- Add HTML test implementation for Slider;
- Add jasmine test spec for Slider (js + fixture).
- Add description for new initialization options;
- Add description for new instance properties;
- Add alternative text for images (updating code samples);
- Update Slider init code sample to include indicatorLabelFunc example.
Copy link
Member

@Smankusors Smankusors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry takes too long, got busy at work 😅

well we already depended with the cash library, so we might as well as use it instead of rewriting it with native JS.

also some formatting issues. I recommend you to use Prettier to format the code 😉

js/slider.js Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
pug/page-contents/media_content.html Outdated Show resolved Hide resolved
pug/page-contents/media_content.html Outdated Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
- Add missing indicatorLabelFunc prop to Slider#options;
- Replace double quotes string by single quotes;
- Replace vanilla JS calls by jQuery functions.
- Replace double quotes string by single quotes;
- Replace vanilla JS calls by jQuery functions.
pug/page-contents/media_content.html Outdated Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
js/slider.js Outdated Show resolved Hide resolved
Mark "indicatorLabelFunc" as optional in docs description and code samples.
Copy link
Member

@Smankusors Smankusors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Smankusors Smankusors merged commit cc26fc7 into materializecss:main Feb 17, 2023
@Smankusors Smankusors added the enhancement New feature or request label Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants