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

Follow ups for accessibility of announcements slider #2580

Merged
merged 8 commits into from
May 2, 2023
Merged
Next Next commit
Stop auto-rotation after first interaction with an arrow button.
Prevent auto-rotation for mobile.

Change settings for auto-rotation.
  • Loading branch information
eugenekasimov committed Apr 27, 2023
commit 1727d86a531b1c626dcd42c02aa3c28b9da53f4d
21 changes: 17 additions & 4 deletions assets/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ class SlideshowComponent extends SliderComponent {
super();
this.sliderControlWrapper = this.querySelector('.slider-buttons');
this.enableSliderLooping = true;
this.arrowButtonWasInteracted = false;
eugenekasimov marked this conversation as resolved.
Show resolved Hide resolved
ludoboludo marked this conversation as resolved.
Show resolved Hide resolved

if (!this.sliderControlWrapper) return;

Expand All @@ -712,12 +713,17 @@ class SlideshowComponent extends SliderComponent {
this.slider.addEventListener('scroll', this.setSlideVisibility.bind(this));
this.setSlideVisibility();

this.mobileLayout = window.matchMedia('(max-width: 749px)');
eugenekasimov marked this conversation as resolved.
Show resolved Hide resolved
this.reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
this.reducedMotion.addEventListener('change', () => {
if (this.slider.getAttribute('data-autoplay') === 'true') this.setAutoPlay();
if (this.slider.getAttribute('data-autoplay') === 'true' && !this.mobileLayout.matches) this.setAutoPlay();
});

if (this.slider.getAttribute('data-autoplay') === 'true') this.setAutoPlay();
window.addEventListener('resize', () => {
this.mobileLayout.matches || this.arrowButtonWasInteracted || this.reducedMotion.matches ? this.pause() : this.play();
});
eugenekasimov marked this conversation as resolved.
Show resolved Hide resolved

if (this.slider.getAttribute('data-autoplay') === 'true' && !this.mobileLayout.matches) this.setAutoPlay();
}

setAutoPlay() {
Expand All @@ -727,13 +733,20 @@ class SlideshowComponent extends SliderComponent {
this.addEventListener('focusin', this.focusInHandling.bind(this));
this.addEventListener('focusout', this.focusOutHandling.bind(this));

this.sliderArrowButtons = this.querySelectorAll('.announcement-bar-slider .slider-button');
eugenekasimov marked this conversation as resolved.
Show resolved Hide resolved
this.sliderArrowButtons.forEach((button) => {
button.addEventListener('click', () => {
this.arrowButtonWasInteracted = true;
}, {once: true});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I don't think you need to add/create a new event listener. We already have an existing listener on the buttons from the SliderComponent.
So you could just add the functionality that you need in the onButtonClick function specifically when it's the announcement bar buttons.

Copy link
Contributor

Choose a reason for hiding this comment

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

Video explanation.

I know you use the once: true on the listener you declared but you should be able to run your specific logic just once in onButtonClick as well by have a check.

Though because it's something that isn't general to slideshows but only in one specific use case (announcement bars), it might be better to keep it separate 🤔

@stufreen do you have a preference yourself ?


if (this.querySelector('.slideshow__autoplay')) {
this.sliderAutoplayButton = this.querySelector('.slideshow__autoplay');
this.sliderAutoplayButton.addEventListener('click', this.autoPlayToggle.bind(this));
this.autoplayButtonIsSetToPlay = true;
this.play();
} else {
this.reducedMotion.matches ? this.pause() : this.play();
this.reducedMotion.matches || this.arrowButtonWasInteracted ? this.pause() : this.play();
}
}

Expand Down Expand Up @@ -782,7 +795,7 @@ class SlideshowComponent extends SliderComponent {
event.target === this.sliderAutoplayButton || this.sliderAutoplayButton.contains(event.target);
if (!this.autoplayButtonIsSetToPlay || focusedOnAutoplayButton) return;
this.play();
} else if (!this.reducedMotion.matches) {
} else if (!this.reducedMotion.matches && !this.arrowButtonWasInteracted && !this.mobileLayout.matches) {
this.play();
}
}
Expand Down
6 changes: 3 additions & 3 deletions sections/announcement-bar.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@
{
"type": "range",
"id": "change_slides_speed",
"min": 3,
"max": 9,
"step": 2,
"min": 5,
"max": 10,
"step": 1,
"unit": "s",
"label": "t:sections.announcement-bar.settings.change_slides_speed.label",
"default": 5
Expand Down