mirror of
https://github.com/Hopiu/vue-material.git
synced 2026-05-17 19:51:06 +00:00
Add keyboard shortcuts to menu
This commit is contained in:
parent
10d329a220
commit
a929aafda9
3 changed files with 45 additions and 2 deletions
|
|
@ -83,7 +83,9 @@ $menu-base-width: 56px;
|
|||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
&:hover {
|
||||
&:hover,
|
||||
&:focus,
|
||||
&.md-highlighted {
|
||||
background-color: rgba(#000, .12);
|
||||
transition: $swift-ease-out;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
class="md-menu-content"
|
||||
@keydown.esc.prevent="close"
|
||||
@keydown.tab.prevent="close"
|
||||
@keydown.up.prevent="highlightItem(highlighted - 1)"
|
||||
@keydown.down.prevent="highlightItem(highlighted + 1)"
|
||||
@keydown.enter.prevent="fireClick"
|
||||
@keydown.space.prevent="fireClick"
|
||||
tabindex="-1">
|
||||
<slot></slot>
|
||||
</div>
|
||||
|
|
@ -10,9 +14,28 @@
|
|||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
highlighted: false,
|
||||
itemsAmount: 0
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
close() {
|
||||
this.highlighted = false;
|
||||
this.$parent.close();
|
||||
},
|
||||
highlightItem(factor) {
|
||||
if (factor >= 1 && factor <= this.itemsAmount) {
|
||||
this.highlighted = factor;
|
||||
} else {
|
||||
this.highlighted = 1;
|
||||
}
|
||||
},
|
||||
fireClick() {
|
||||
if (this.highlighted > 0) {
|
||||
this.$children[this.highlighted - 1].$el.click();
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
<template>
|
||||
<div class="md-menu-item" @click="close">
|
||||
<div
|
||||
class="md-menu-item"
|
||||
:class="classes"
|
||||
@click="close">
|
||||
<div class="md-menu-item-content">
|
||||
<slot></slot>
|
||||
</div>
|
||||
|
|
@ -8,6 +11,18 @@
|
|||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
index: 0
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
classes() {
|
||||
return {
|
||||
'md-highlighted': this.index === this.$parent.highlighted
|
||||
};
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
close() {
|
||||
this.$emit('click');
|
||||
|
|
@ -20,6 +35,9 @@
|
|||
|
||||
throw new Error('You must wrap the md-menu-item in a md-menu-content');
|
||||
}
|
||||
|
||||
this.$parent.itemsAmount++;
|
||||
this.index = this.$parent.itemsAmount;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue