Skip to content

Commit

Permalink
Refactor #3092
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Oct 18, 2022
1 parent 14ca020 commit e03ac66
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/components/dock/DockSub.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
@mouseleave="onListMouseLeave"
>
<template v-for="(processedItem, index) of model" :key="index">
<div class="p-menuitem-content">
<li
:id="getItemId(index)"
:class="itemClass(processedItem, index, getItemId(index))"
role="menuitem"
:aria-label="processedItem.label"
:aria-disabled="disabled(processedItem)"
@click="onItemClick($event, processedItem)"
@mouseenter="onItemMouseEnter(index)"
>
<li
:id="getItemId(index)"
:class="itemClass(processedItem, index, getItemId(index))"
role="menuitem"
:aria-label="processedItem.label"
:aria-disabled="disabled(processedItem)"
@click="onItemClick($event, processedItem)"
@mouseenter="onItemMouseEnter(index)"
>
<div class="p-menuitem-content">
<template v-if="!templates['item']">
<router-link v-if="processedItem.to && !disabled(processedItem)" v-slot="{ navigate, href, isActive, isExactActive }" :to="processedItem.to" custom>
<a
Expand All @@ -51,8 +51,8 @@
</a>
</template>
<component v-else :is="templates['item']" :item="processedItem" :index="index"></component>
</li>
</div>
</div>
</li>
</template>
</ul>
</div>
Expand Down Expand Up @@ -128,9 +128,12 @@ export default {
navigate && navigate(event);
},
onItemClick(event, processedItem) {
console.log(processedItem);
if (this.isSameMenuItem(event)) {
const command = this.getItemProp(processedItem, 'command');
console.log(processedItem);
command && command({ originalEvent: event, item: processedItem.item });
}
},
Expand Down Expand Up @@ -210,24 +213,16 @@ export default {
onEndKey() {
this.changeFocusedOptionIndex(DomHandler.find(this.$refs.list, 'li.p-dock-item:not(.p-disabled)').length - 1);
},
onSpaceKey(event) {
const menuitems = DomHandler.find(this.$refs.list, 'li.p-dock-item');
const matchedOptionIndex = [...menuitems].findIndex((link) => link.id === this.focusedOptionId);
onSpaceKey() {
const element = DomHandler.findSingle(this.$refs.list, `li[id="${`${this.focusedOptionIndex}`}"]`);
const anchorElement = element && DomHandler.findSingle(element, '.p-dock-action');
if (this.model[matchedOptionIndex].to) {
this.$router.push(this.model[matchedOptionIndex].to);
} else if (this.model[matchedOptionIndex].url) {
menuitems[matchedOptionIndex].children[0].children[0].click();
} else {
this.onItemClick(event, this.model[matchedOptionIndex]);
}
anchorElement ? anchorElement.click() : element && element.click();
},
findNextOptionIndex(index) {
const menuitems = DomHandler.find(this.$refs.list, 'li.p-dock-item:not(.p-disabled)');
const matchedOptionIndex = [...menuitems].findIndex((link) => link.id === index);
console.log(matchedOptionIndex);
return matchedOptionIndex > -1 ? matchedOptionIndex + 1 : 0;
},
findPrevOptionIndex(index) {
Expand Down

0 comments on commit e03ac66

Please sign in to comment.