davidjerleke / embla-carousel

A lightweight carousel library with fluid motion and great swipe precision.
https://www.embla-carousel.com
MIT License
5.5k stars 167 forks source link

Support using tab(focus) to select and navigate carousel #456

Closed winston0410 closed 11 months ago

winston0410 commented 1 year ago

Feature request is related to

Is your feature request related to an issue?

Right now when Tab is used to navigate, and if focusable element is located in the carousel, the slides will be navigated, but the embla.selectedScrollSnap is still 0.

Describe the solution you'd like

Listen on:focus and set selectedScrollSnap

Describe alternatives you've considered

I have tried to use on:focus event on those focusable element, and set the index with embla.scrollTo. But since focus event is only firing after an element received focus(i.e navigated to a new element), embla.scrollTo does not work well.

Basically, I think we need a method that manipulate embla.selectedScrollSnap without actually scrolling to that slide.

Additional context

Add any other context or screenshots about the feature request here.

davidjerleke commented 1 year ago

Please read the conversation and this.

winston0410 commented 1 year ago

Hey David thanks you for your prompt reply. I have read that issue but I don't believe they are duplicate. Are you suggesting that using scrollNext or scollPrev is the solution here?

From what I can see, using Tab for navigation is not really the same with arrowkeys with keydown event, as we have to update after that navigation has happened, but for arrowkeys we are dealing with the event before that navigation on:keydown.

davidjerleke commented 1 year ago

Ah sorry about that @winston0410,

I was a bit too fast there. This was the comment I wanted to share. The title of the issue doesn't seem related though so I understand why you didn't find it 😄.

Best, David

winston0410 commented 1 year ago

Yes indeed that is not what I would have found with out your help, thank you so much. I have tried that plugin and seems like it is working well, except the type is a little bit off now. Would you accept a PR if I fix the type for that?

davidjerleke commented 11 months ago

@winston0410 this feature will be released with v8.0.0-rc12.

davidjerleke commented 11 months ago

@winston0410 this feature has been released with v8.0.0-rc12.