return
}
+ // Don't hijack modifier+arrow shortcuts (e.g. Alt+Left/Right for browser
+ // history navigation); only the bare keys drive tablist navigation.
+ if (event.altKey || event.ctrlKey || event.metaKey) {
+ return
+ }
+
event.stopPropagation()// stopPropagation/preventDefault both added to support up/down keys without scrolling the page
event.preventDefault()
expect(spyPrevent).not.toHaveBeenCalled()
})
+ it('if arrow key is pressed with a modifier (e.g. Alt+Left), ignore it', () => {
+ fixtureEl.innerHTML = [
+ '<ul class="nav">',
+ ' <li class="nav-link" data-bs-toggle="tab"></li>',
+ '</ul>'
+ ].join('')
+
+ const tabEl = fixtureEl.querySelector('.nav-link')
+ const tab = new Tab(tabEl)
+
+ const keydown = createEvent('keydown')
+ keydown.key = 'ArrowLeft'
+ keydown.altKey = true
+ const spyStop = spyOn(Event.prototype, 'stopPropagation').and.callThrough()
+ const spyPrevent = spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spyGet = spyOn(tab, '_getChildren')
+
+ tabEl.dispatchEvent(keydown)
+
+ expect(spyGet).not.toHaveBeenCalled()
+ expect(spyStop).not.toHaveBeenCalled()
+ expect(spyPrevent).not.toHaveBeenCalled()
+ })
+
it('if keydown event is right/down arrow, handle it', () => {
fixtureEl.innerHTML = [
'<div class="nav">',
By default, the menu is closed when clicking inside or outside the menu. You can use the `autoClose` option to change this behavior of the menu.
+Regardless of the `autoClose` setting, pressing <kbd>Esc</kbd> while focus is within the menu (its toggle or items) closes the menu and returns focus to the toggle.
+
<Example class="d-flex flex-wrap gap-2" code={`<div class="btn-group">
<button class="btn-solid theme-secondary" type="button" data-bs-toggle="menu" data-bs-auto-close="true" aria-expanded="false">
Default menu