From c40fc4e4efbeafe3f30469adec1033484112e0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20B=C3=BCschlen?= Date: Wed, 19 Jun 2024 15:54:11 +0200 Subject: [PATCH] feat(menu): avoid captured key events from navigating the whole page (#191) --- src/components/dropdown/Dropdown.js | 5 +++-- src/components/dropdown/stories/dropdown.stories.js | 4 ++++ src/components/menu/Menu.js | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/dropdown/Dropdown.js b/src/components/dropdown/Dropdown.js index 1b238008..344dcb44 100644 --- a/src/components/dropdown/Dropdown.js +++ b/src/components/dropdown/Dropdown.js @@ -75,8 +75,9 @@ export class LeuDropdown extends LeuElement { } } - async _keyUpToggleHandler(event) { + async _keyDownToggleHandler(event) { if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) { + event.preventDefault() const menu = this._getMenu() const menuItems = menu.getMenuItems() @@ -144,7 +145,7 @@ export class LeuDropdown extends LeuElement { expanded=${this.expanded ? "true" : "false"} ?active=${this.expanded} @click=${this._handleToggleClick} - @keyup=${this._keyUpToggleHandler} + @keydown=${this._keyDownToggleHandler} > ${hasIcon ? html`` : nothing} ${this.label} ${icon ? html`` : nothing} + OGD Ressource Als CSV Tabelle Als XLS Tabelle
diff --git a/src/components/menu/Menu.js b/src/components/menu/Menu.js index c0f093ce..a350a86d 100644 --- a/src/components/menu/Menu.js +++ b/src/components/menu/Menu.js @@ -81,6 +81,8 @@ export class LeuMenu extends LeuElement { _handleKeyDown(event) { if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) { + event.preventDefault() + const menuItems = this.getMenuItems() let index = menuItems.findIndex((menuItem) => menuItem.tabIndex === 0)