From 378b6503d288e196f8eb96de1200ab0b13ad6015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Wed, 19 Oct 2022 22:48:18 +0300 Subject: [PATCH] Refactor #3085 --- src/components/menu/Menu.vue | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/menu/Menu.vue b/src/components/menu/Menu.vue index 6f98fd0ec9..9f245826a5 100644 --- a/src/components/menu/Menu.vue +++ b/src/components/menu/Menu.vue @@ -177,11 +177,11 @@ export default { break; case 'Enter': - this.onEnterKey(); + this.onEnterKey(event); break; case 'Space': - this.onSpaceKey(); + this.onSpaceKey(event); break; case 'Tab': @@ -199,10 +199,16 @@ export default { event.preventDefault(); }, onArrowUpKey(event) { - const optionIndex = this.findPrevOptionIndex(this.focusedOptionIndex); - - this.changeFocusedOptionIndex(optionIndex); - event.preventDefault(); + if (event.altKey && this.popup) { + DomHandler.focus(this.target); + this.hide(); + event.preventDefault(); + } else { + const optionIndex = this.findPrevOptionIndex(this.focusedOptionIndex); + + this.changeFocusedOptionIndex(optionIndex); + event.preventDefault(); + } }, onHomeKey(event) { this.changeFocusedOptionIndex(0); @@ -212,15 +218,17 @@ export default { this.changeFocusedOptionIndex(DomHandler.find(this.container, 'li.p-menuitem:not(.p-disabled)').length - 1); event.preventDefault(); }, - onEnterKey() { + onEnterKey(event) { const element = DomHandler.findSingle(this.list, `li[id="${`${this.focusedOptionIndex}`}"]`); const anchorElement = element && DomHandler.findSingle(element, '.p-menuitem-action'); this.popup && DomHandler.focus(this.target); anchorElement ? anchorElement.click() : element && element.click(); + + event.preventDefault(); }, - onSpaceKey() { - this.onEnterKey(); + onSpaceKey(event) { + this.onEnterKey(event); }, findNextOptionIndex(index) { const links = DomHandler.find(this.container, 'li.p-menuitem:not(.p-disabled)'); @@ -402,7 +410,7 @@ export default { list-style: none; } -.p-menu .p-menuitem-link { +.p-menu .p-menuitem-action { cursor: pointer; display: flex; align-items: center;