title: Bootstrap carousel keyboard buttons only work after clicking arrow on screen
body: <p>Does anyone know how to override the default bootstrap carousel functionality of keyboard left and right buttons working only after first clicking one of the arrows on the screen.</p>
  <p>I have rows of cards which when clicked opens a modal and inside that modal I have my carousel. I'd like the user to immediately be able to use the keyboard arrows and not have to click the arrows on the screen to enable the keyboard arrows to work. This appears to be the default behavior.</p>
  <p>I've tried using <code>$(#exampleId).focus()</code> on various elements in the modal and carousel but no luck getting it to work thus far.</p>
  <p>The default behavior can be seen in the bootstrap carousel doc:
  <a href="https://getbootstrap.com/docs/5.0/components/carousel/#with-controls" rel="nofollow noreferrer">https://getbootstrap.com/docs/5.0/components/carousel/#with-controls</a></p>
  <p>Bootstrap-5 Carousel with controls code:</p>
  <pre><code>&lt;div id=&quot;carouselExampleControls&quot; class=&quot;carousel slide&quot; data-bs-ride=&quot;carousel&quot;&gt;
    &lt;div class=&quot;carousel-inner&quot;&gt;
      &lt;div class=&quot;carousel-item active&quot;&gt;
        &lt;img src=&quot;...&quot; class=&quot;d-block w-100&quot; alt=&quot;...&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;carousel-item&quot;&gt;
        &lt;img src=&quot;...&quot; class=&quot;d-block w-100&quot; alt=&quot;...&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;carousel-item&quot;&gt;
        &lt;img src=&quot;...&quot; class=&quot;d-block w-100&quot; alt=&quot;...&quot;&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;button class=&quot;carousel-control-prev&quot; type=&quot;button&quot; data-bs-target=&quot;#carouselExampleControls&quot; data-bs-slide=&quot;prev&quot;&gt;
      &lt;span class=&quot;carousel-control-prev-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;
      &lt;span class=&quot;visually-hidden&quot;&gt;Previous&lt;/span&gt;
    &lt;/button&gt;
    &lt;button class=&quot;carousel-control-next&quot; type=&quot;button&quot; data-bs-target=&quot;#carouselExampleControls&quot; data-bs-slide=&quot;next&quot;&gt;
      &lt;span class=&quot;carousel-control-next-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;
      &lt;span class=&quot;visually-hidden&quot;&gt;Next&lt;/span&gt;
    &lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Edit:
  After following bootstrap documentation link you'll see that you can only slide the carousel using the keyboard <em>after</em> clicking one of the controls on the carousel &quot;&lt;&quot; or &quot;&gt;&quot;. If you just start by using your left or right arrow keyboard buttons the carousel doesn't respond.</p>