question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navigating with arrow keys affects all carousels, not just the carousel in focus

See original GitHub issue

I’m creating a few Glide sliders on the page like so:

import Glide from '@glidejs/glide';

const sliders = document.querySelectorAll('.glide');

sliders.forEach((slider) => {
  new Glide(slider).mount();
});

The sliders all work perfectly well independently, but when I try to focus on one and navigate with the keyboard, all of the sliders are affected and change to either the next or previous slide.

Pressing the arrow keys should only affect the slider that the user is focused into.

From inspecting the source code it looks like this may be because Glide is attaching a keyup listener on the document element, rather on each individual .glide element.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:14
  • Comments:8

github_iconTop GitHub Comments

1reaction
ghostcommented, Oct 14, 2019

Disable keyboard events globally for Glide and then attach specific events when you mount the individual sliders.

import Glide from '@glidejs/glide';

const sliders = document.querySelectorAll('.glide');

let sliderObj = {};

sliders.forEach((slider, i) => {
    // Add glide to the object for reference, disable global keyboard
    sliderObj[i] = new Glide(slider, {
        type: 'carousel',
        keyboard: false
    });
    // Attatch event listener and instruct slide to go left and right
    slider.addEventListener('keyup', (e) => {
        if (e.keyCode == 39) this.sliderObj[i].go('>');
        if (e.keyCode == 37) this.sliderObj[i].go('<');
    });
    // Mount
    sliderObj[i].mount();
});
0reactions
Ceyarcommented, Jul 20, 2021

Mmmh, using keyup eventListener will let me use keyboard. I have to click on the carousel to get he keyboard enabled.

Did someone had the same problem and fixed it?

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Controls & Interaction • Carousels • WAI Web ... - W3C
In the first steps the slide show is prepared to hide all content but the first slide. Then “left” and “right” arrows are...
Read more >
If you must use a carousel, make it accessible - Alison Walden
Sighted users perceive carousel content as a series of panels usually navigated via arrow buttons. The main carousel accessibility consideration for sighted ...
Read more >
How to build a more accessible carousel or slider
Many carousels do not hide their non-visible slides from all users, ... Don't use custom keyboard controls, like arrow keys for navigation.
Read more >
Accessibility - Splide
From the version 4, custom keyboard shortcuts, such as arrow keys to move a carousel, are disabled by default, but only the shortcuts...
Read more >
Creating an Accessible Image Carousel
Carousels don't have to be bad, but we have a culture of making them ... Focus the carousel and use your arrow keys...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found