Skip to content

Commit

Permalink
Refactor #3085
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Oct 19, 2022
1 parent 6cfe482 commit 378b650
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/components/menu/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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);
Expand All @@ -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)');
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 378b650

Please sign in to comment.