Allow selecting menu items with space (#1429)

* allow selecting menu items with space; #1423

* update PR
pull/1399/head
Cory LaViska 2023-07-06 10:36:29 -04:00 zatwierdzone przez GitHub
rodzic 8ffbd02db7
commit c9e644f3fc
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 3 dodań i 7 usunięć

Wyświetl plik

@ -15,6 +15,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti
## Next
- Added tests for `<sl-qr-code>` [#1416]
- Added support for pressing [[Space]] to select/toggle selected `<sl-menu-item>` elements [#1429]
- Fixed a bug in `<sl-qr-code>` where the `background` attribute was never passed to the QR code [#1416]
- Fixed a bug in `<sl-dropdown>` where aria attributes were incorrectly applied to the default `<slot>` causing Lighthouse errors [#1417]
- Fixed a bug in `<sl-carousel>` that caused navigation to work incorrectly in some case [#1420]

Wyświetl plik

@ -45,8 +45,8 @@ export default class SlMenu extends ShoelaceElement {
}
private handleKeyDown(event: KeyboardEvent) {
// Make a selection when pressing enter
if (event.key === 'Enter') {
// Make a selection when pressing enter or space
if (event.key === 'Enter' || event.key === ' ') {
const item = this.getCurrentItem();
event.preventDefault();
@ -54,11 +54,6 @@ export default class SlMenu extends ShoelaceElement {
item?.click();
}
// Prevent scrolling when space is pressed
if (event.key === ' ') {
event.preventDefault();
}
// Move the selection when pressing down or up
if (['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) {
const items = this.getAllItems();