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

Is useKeyboardArrows prop supported. #514

Closed
Sumit2105 opened this issue Oct 9, 2020 · 4 comments
Closed

Is useKeyboardArrows prop supported. #514

Sumit2105 opened this issue Oct 9, 2020 · 4 comments

Comments

@Sumit2105
Copy link

I want an ability to navigate through arrows of the keyboard. In many of the documentation, I can see useKeyboardArrows, Provides the ability to do the same. But this doesn't seem to work for me.

@nightflash
Copy link

For some reason, you have to click on the image before kb navigation will work.

@blainegarrett
Copy link
Contributor

blainegarrett commented Dec 4, 2020

Is it possible to expose a ref to trigger the touch event to give the carousel focus?
In presentation mode, it would be great to just hit the arrow keys w/o first having to interact with the component.
There doesn't seem to be any public refs available.

Update:
As it was critical for me to figure this out, a seemingly hacky way to achieve this is to use a ref on an element you have control over (such as a slide) and then trigger focus on the .carousel-root ancestor element.

  const firstSlideRef = React.useRef<HTMLDivElement>(null);

  useEffect(() => {  
    firstSlideRef.current.closest('.carousel-root').focus(); // finds closest ancestor with matching selector
   }, []);

      <Carousel useKeyboardArrows>
                   <div ref={firstSlideRef} key="content-0">first slide content</div>
       </Carousel>

When digging into this, I found it useful to put a css psuedo class on the .carousel-root element to expose if it had focus or not. Pardon the JSS syntax (I'm working within material-ui).

    '@global': {
      '.carousel-root': {
        '&:focus': {
          border: '3px solid green',
        },
      },

@leandrowd
Copy link
Owner

leandrowd commented Dec 4, 2020 via email

blainegarrett added a commit to blainegarrett/react-responsive-carousel that referenced this issue Dec 5, 2020
leandrowd added a commit that referenced this issue Dec 5, 2020
#514 Add autoFocus prop so useKeyboardArrows works without clicking first
@leandrowd
Copy link
Owner

All done, published as 3.2.11 - thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants