owntone-server/web-src/src/components/DropdownMenu.vue

51 lines
1.2 KiB
Vue
Raw Normal View History

<template>
2022-05-20 07:44:22 -04:00
<div v-click-away="onClickOutside" class="dropdown" :class="{ 'is-active': is_active }">
<div class="dropdown-trigger">
2022-05-20 07:44:22 -04:00
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu" @click="is_active = !is_active">
<span v-text="option.name" />
<mdicon class="icon" name="chevron-down" size="16" />
</button>
</div>
<div id="dropdown-menu" class="dropdown-menu" role="menu">
<div class="dropdown-content">
2022-05-20 07:44:22 -04:00
<a v-for="option in options" :key="option.id" class="dropdown-item" :class="{ 'is-active': modelValue === option.id }" @click="select(option)" v-text="option.name" />
</div>
</div>
</div>
</template>
<script>
export default {
name: 'DropdownMenu',
2022-02-19 00:18:01 -05:00
props: ['modelValue', 'options'],
emits: ['update:modelValue'],
data() {
return {
is_active: false
}
},
2022-05-20 07:44:22 -04:00
computed: {
option: {
get() {
return this.options.find((option) => option.id === this.modelValue)
}
}
},
methods: {
onClickOutside(event) {
this.is_active = false
},
select(option) {
this.is_active = false
2022-05-20 07:44:22 -04:00
this.$emit('update:modelValue', option.id)
}
}
}
</script>
<style></style>