Improve dropdown
This commit is contained in:
parent
a135c12f03
commit
712da967ce
2 changed files with 14 additions and 4 deletions
|
@ -7,19 +7,24 @@ const emit = defineEmits<{
|
|||
select: [item: string | number]
|
||||
}>()
|
||||
|
||||
const open = ref(false)
|
||||
const [open, toggleOpen] = useToggle()
|
||||
|
||||
const select = function (item) {
|
||||
emit('select', typeof item === 'object' ? item.id : item)
|
||||
toggleOpen(false)
|
||||
}
|
||||
|
||||
const dropdown = ref(null)
|
||||
onClickOutside(dropdown, () => toggleOpen(false))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PrimaryButton @click="open = !open">
|
||||
<div ref="dropdown">
|
||||
<PrimaryButton @click="toggleOpen()">
|
||||
<slot /> ↓
|
||||
</PrimaryButton>
|
||||
|
||||
<!--suppress VueUnrecognizedDirective -->
|
||||
<ul v-show="open" v-bind="$attrs">
|
||||
<li v-for="(item, index) in options" :key="index" @click="select(item)">
|
||||
<template v-if="typeof item === 'object'">
|
||||
|
|
|
@ -4,6 +4,8 @@ import medias from '@data/medias'
|
|||
const mediaList = computed(() => {
|
||||
return medias.filter((m) => m.type === 'book')
|
||||
})
|
||||
|
||||
const category = ref('Books')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -15,7 +17,10 @@ const mediaList = computed(() => {
|
|||
<TableTh>Copies</TableTh>
|
||||
<TableTh>Checked Out</TableTh>
|
||||
<TableTh actions>
|
||||
<Dropdown :options="['books', 'films', 'albums']">Type</Dropdown>
|
||||
<Dropdown :options="['Books', 'Films', 'Albums']"
|
||||
@select="(i) => category = (i as string)">
|
||||
{{ category }}
|
||||
</Dropdown>
|
||||
<PrimaryButton>Add New</PrimaryButton>
|
||||
</TableTh>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in a new issue