Skip to content

Carousel - is it possible to turn off keyboard navigation? #14468

Closed

Description

I am finding that I cannot turn off keyboard navigation within the carousel. The carousel panes are sliding/changing when I use the arrow keys and I can't find a way to turn this behavior off.

I can hook into .on('keydown.bs.carousel' event, but unfortunately, this fires after the carousel has executed both 'slide; and 'slid' events.

Is there another event I can hook into to determine how the carousel is being advanced?

Activity

  1. cvrebert commented on Aug 27, 2014

    @cvrebert
    Collaborator

    I suppose we could add a boolean keyboard option like the modal plugin has.
    Keep in mind that disabling keyboard control hurts accessibility for your users.

  2. hnrch02 commented on Aug 29, 2014

    @hnrch02
    Collaborator

    To completely disable keyboard navigation you could do this:

    $('#myCarousel').off('keydown.bs.carousel');

    But that only works if you initialize the carousel yourself and do not rely on the data-api, because it waits for the page to load until the carousel is initialized and therefore you'd need to wrap it in a $(window).on('load'), which is kinda messy. So I second a keyboard option.

  3. added a commit that references this issue on Oct 3, 2014
    038a63b
  4. fat commented on Oct 3, 2014

    @fat
    Member

    you have several options:

    1. $('#myCarousel').off('keydown.bs.carousel');
    2. preventDefault on the 'slide.bs.carousel' event
    3. $.fn.carousel.Constructor.prototype.keydown = function () {}

    It seems like a pretty rare case that you would want to turn accessibility off like this, so I'm not thrilled about adding an option for it

  5. cvrebert commented on Oct 3, 2014

    @cvrebert
    Collaborator

    At any rate, the new option to disable the carousel's handling of keyboard events was approved: #14590.

  6. added a commit that references this issue on Oct 9, 2014
    e2e91e4
  7. ugenegrg commented on Sep 26, 2016

    @ugenegrg

    Allright, using data attr or via js, it works, but there is an strange issue in my case.
    I have disabled the key reaction in caraousel which is working fine, but i have a popup in the lets's say 5th slide, and used the bootstrap modal for popup. Now the problem is when bootstrap modal is showing, the keyboard false does not prevent the carousel from sliding? Any help is appreciated. Also tried the solutions to prevent action using event listener and others as below.

    window.addEventListener("keydown", function(e) { // space and arrow keys if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) { e.preventDefault(); } }, false);

    By the way my pop modal is outside of the the carousel. It is just triggered from one of the carousel slide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature, or a change to how an existing one worksjsJavaScript or TypeScript sources and plugins

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions