fix(components)!: rename select to onSelect on items

This commit is contained in:
Benjamin Canac
2024-10-15 13:10:58 +02:00
parent 6af276ef38
commit b39c4d127e
21 changed files with 76 additions and 125 deletions

View File

@@ -89,7 +89,7 @@ const groups = ref([
'meta', 'meta',
'N' 'N'
], ],
select: () => { onSelect() {
console.log('Add new file') console.log('Add new file')
} }
}, },
@@ -101,7 +101,7 @@ const groups = ref([
'meta', 'meta',
'F' 'F'
], ],
select: () => { onSelect() {
console.log('Add new folder') console.log('Add new folder')
} }
}, },
@@ -113,7 +113,7 @@ const groups = ref([
'meta', 'meta',
'H' 'H'
], ],
select: () => { onSelect() {
console.log('Add hashtag') console.log('Add hashtag')
} }
}, },
@@ -125,7 +125,7 @@ const groups = ref([
'meta', 'meta',
'L' 'L'
], ],
select: () => { onSelect() {
console.log('Add label') console.log('Add label')
} }
} }
@@ -134,8 +134,8 @@ const groups = ref([
]) ])
function onSelect(item: any) { function onSelect(item: any) {
if (item.select) { if (item.onSelect) {
item.select() item.onSelect()
} else if (item.to) { } else if (item.to) {
if (typeof item.to === 'string' && (item.target === '_blank' || item.to.startsWith('http'))) { if (typeof item.to === 'string' && (item.target === '_blank' || item.to.startsWith('http'))) {
window.open(item.to, item.target || '_blank') window.open(item.to, item.target || '_blank')

View File

@@ -123,12 +123,16 @@ const items = [{
label: 'Save', label: 'Save',
icon: 'i-heroicons-document-arrow-down', icon: 'i-heroicons-document-arrow-down',
kbds: ['meta', 'S'], kbds: ['meta', 'S'],
select: () => save() onSelect() {
save()
}
}, { }, {
label: 'Copy', label: 'Copy',
icon: 'i-heroicons-document-duplicate', icon: 'i-heroicons-document-duplicate',
kbds: ['meta', 'C'], kbds: ['meta', 'C'],
select: () => copy() onSelect() {
copy()
}
}] }]
defineShortcuts(extractShortcuts(items)) defineShortcuts(extractShortcuts(items))

View File

@@ -43,7 +43,7 @@ Each group takes some `items` as an array of objects with the following properti
- `kbds?: string[] | KbdProps[]`{lang="ts-type"} - `kbds?: string[] | KbdProps[]`{lang="ts-type"}
- `disabled?: boolean`{lang="ts-type"} - `disabled?: boolean`{lang="ts-type"}
- [`slot?: string`{lang="ts-type"}](#with-custom-slot) - [`slot?: string`{lang="ts-type"}](#with-custom-slot)
- `select?(e?: Event): void`{lang="ts-type"} - `onSelect?(e?: Event): void`{lang="ts-type"}
::component-code ::component-code
--- ---

View File

@@ -26,7 +26,7 @@ Use the `items` prop as an array of objects with the following properties:
- `disabled?: boolean`{lang="ts-type"} - `disabled?: boolean`{lang="ts-type"}
- `class?: any`{lang="ts-type"} - `class?: any`{lang="ts-type"}
- [`slot?: string`{lang="ts-type"}](#with-custom-slot) - [`slot?: string`{lang="ts-type"}](#with-custom-slot)
- `select?(e: Event): void`{lang="ts-type"} - `onSelect?(e: Event): void`{lang="ts-type"}
You can also pass any property from the [Link](/components/link#props) component such as `to`, `target`, etc. You can also pass any property from the [Link](/components/link#props) component such as `to`, `target`, etc.
@@ -207,13 +207,13 @@ const items = [
[{ [{
label: 'Show Sidebar', label: 'Show Sidebar',
kbds: ['meta', 'S'], kbds: ['meta', 'S'],
select() { onSelect() {
console.log('Show Sidebar clicked') console.log('Show Sidebar clicked')
} }
}, { }, {
label: 'Show Toolbar', label: 'Show Toolbar',
kbds: ['shift', 'meta', 'D'], kbds: ['shift', 'meta', 'D'],
select() { onSelect() {
console.log('Show Toolbar clicked') console.log('Show Toolbar clicked')
} }
}, { }, {
@@ -232,25 +232,25 @@ const items = [
children: [[{ children: [[{
label: 'View Source', label: 'View Source',
kbds: ['option', 'meta', 'U'], kbds: ['option', 'meta', 'U'],
select() { onSelect() {
console.log('View Source clicked') console.log('View Source clicked')
} }
}, { }, {
label: 'Developer Tools', label: 'Developer Tools',
kbds: ['option', 'meta', 'I'], kbds: ['option', 'meta', 'I'],
select() { onSelect() {
console.log('Developer Tools clicked') console.log('Developer Tools clicked')
} }
}], [{ }], [{
label: 'Inspect Elements', label: 'Inspect Elements',
kbds: ['option', 'meta', 'C'], kbds: ['option', 'meta', 'C'],
select() { onSelect() {
console.log('Inspect Elements clicked') console.log('Inspect Elements clicked')
} }
}], [{ }], [{
label: 'JavaScript Console', label: 'JavaScript Console',
kbds: ['option', 'meta', 'J'], kbds: ['option', 'meta', 'J'],
select() { onSelect() {
console.log('JavaScript Console clicked') console.log('JavaScript Console clicked')
} }
}]] }]]

View File

@@ -26,7 +26,7 @@ Use the `items` prop as an array of objects with the following properties:
- `disabled?: boolean`{lang="ts-type"} - `disabled?: boolean`{lang="ts-type"}
- `class?: any`{lang="ts-type"} - `class?: any`{lang="ts-type"}
- [`slot?: string`{lang="ts-type"}](#with-custom-slot) - [`slot?: string`{lang="ts-type"}](#with-custom-slot)
- `select?(e: Event): void`{lang="ts-type"} - `onSelect?(e: Event): void`{lang="ts-type"}
You can also pass any property from the [Link](/components/link#props) component such as `to`, `target`, etc. You can also pass any property from the [Link](/components/link#props) component such as `to`, `target`, etc.
@@ -306,14 +306,14 @@ const items = [{
label: 'Invite by email', label: 'Invite by email',
icon: 'i-heroicons-paper-airplane', icon: 'i-heroicons-paper-airplane',
kbds: ['meta', 'e'], kbds: ['meta', 'e'],
select() { onSelect() {
console.log('Invite by email clicked') console.log('Invite by email clicked')
} }
}, { }, {
label: 'Invite by link', label: 'Invite by link',
icon: 'i-heroicons-link', icon: 'i-heroicons-link',
kbds: ['meta', 'i'], kbds: ['meta', 'i'],
select() { onSelect() {
console.log('Invite by link clicked') console.log('Invite by link clicked')
} }
}] }]
@@ -321,7 +321,7 @@ const items = [{
label: 'New team', label: 'New team',
icon: 'i-heroicons-plus', icon: 'i-heroicons-plus',
kbds: ['meta', 'n'], kbds: ['meta', 'n'],
select() { onSelect() {
console.log('New team clicked') console.log('New team clicked')
} }
}] }]

View File

@@ -53,7 +53,7 @@ You can also pass an array of objects with the following properties:
- [`avatar?: AvatarProps`{lang="ts-type"}](#with-avatar-in-items) - [`avatar?: AvatarProps`{lang="ts-type"}](#with-avatar-in-items)
- [`chip?: ChipProps`{lang="ts-type"}](#with-chip-in-items) - [`chip?: ChipProps`{lang="ts-type"}](#with-chip-in-items)
- `disabled?: boolean`{lang="ts-type"} - `disabled?: boolean`{lang="ts-type"}
- `select?(e: Event): void`{lang="ts-type"} - `onSelect?(e: Event): void`{lang="ts-type"}
::component-code ::component-code
--- ---

View File

@@ -25,7 +25,7 @@ Use the `items` prop as an array of objects with the following properties:
- `disabled?: boolean`{lang="ts-type"} - `disabled?: boolean`{lang="ts-type"}
- `class?: any`{lang="ts-type"} - `class?: any`{lang="ts-type"}
- [`slot?: string`{lang="ts-type"}](#with-custom-slot) - [`slot?: string`{lang="ts-type"}](#with-custom-slot)
- `select?(e: Event): void`{lang="ts-type"} - `onSelect?(e: Event): void`{lang="ts-type"}
You can also pass any property from the [Link](/components/link#props) component such as `to`, `target`, etc. You can also pass any property from the [Link](/components/link#props) component such as `to`, `target`, etc.
@@ -130,7 +130,7 @@ Each item can take a `children` array of objects with the following properties t
- `description?: string` - `description?: string`
- `icon?: string` - `icon?: string`
- `class?: any` - `class?: any`
- `select?(e: Event): void` - `onSelect?(e: Event): void`
:: ::
### Orientation ### Orientation

View File

@@ -55,7 +55,7 @@ You can also pass an array of objects with the following properties:
- [`avatar?: AvatarProps`{lang="ts-type"}](#with-avatar-in-items) - [`avatar?: AvatarProps`{lang="ts-type"}](#with-avatar-in-items)
- [`chip?: ChipProps`{lang="ts-type"}](#with-chip-in-items) - [`chip?: ChipProps`{lang="ts-type"}](#with-chip-in-items)
- `disabled?: boolean`{lang="ts-type"} - `disabled?: boolean`{lang="ts-type"}
- `select?(e: Event): void`{lang="ts-type"} - `onSelect?(e: Event): void`{lang="ts-type"}
::component-code ::component-code
--- ---

View File

@@ -24,13 +24,13 @@ const items = [
[{ [{
label: 'Show Sidebar', label: 'Show Sidebar',
kbds: ['meta', 'S'], kbds: ['meta', 'S'],
select() { onSelect() {
console.log('Show Sidebar clicked') console.log('Show Sidebar clicked')
} }
}, { }, {
label: 'Show Toolbar', label: 'Show Toolbar',
kbds: ['shift', 'meta', 'D'], kbds: ['shift', 'meta', 'D'],
select() { onSelect() {
console.log('Show Toolbar clicked') console.log('Show Toolbar clicked')
} }
}, { }, {
@@ -49,25 +49,25 @@ const items = [
children: [[{ children: [[{
label: 'View Source', label: 'View Source',
kbds: ['option', 'meta', 'U'], kbds: ['option', 'meta', 'U'],
select() { onSelect() {
console.log('View Source clicked') console.log('View Source clicked')
} }
}, { }, {
label: 'Developer Tools', label: 'Developer Tools',
kbds: ['option', 'meta', 'I'], kbds: ['option', 'meta', 'I'],
select() { onSelect() {
console.log('Developer Tools clicked') console.log('Developer Tools clicked')
} }
}], [{ }], [{
label: 'Inspect Elements', label: 'Inspect Elements',
kbds: ['option', 'meta', 'C'], kbds: ['option', 'meta', 'C'],
select() { onSelect() {
console.log('Inspect Elements clicked') console.log('Inspect Elements clicked')
} }
}], [{ }], [{
label: 'JavaScript Console', label: 'JavaScript Console',
kbds: ['option', 'meta', 'J'], kbds: ['option', 'meta', 'J'],
select() { onSelect() {
console.log('JavaScript Console clicked') console.log('JavaScript Console clicked')
} }
}]] }]]

View File

@@ -13,7 +13,7 @@ const items = [
label: 'Profile', label: 'Profile',
icon: 'i-heroicons-user', icon: 'i-heroicons-user',
slot: 'custom' as const, slot: 'custom' as const,
select(e: Event) { onSelect(e: Event) {
e.preventDefault() e.preventDefault()
console.log('Profile clicked') console.log('Profile clicked')
} }
@@ -21,14 +21,14 @@ const items = [
label: 'Billing', label: 'Billing',
icon: 'i-heroicons-credit-card', icon: 'i-heroicons-credit-card',
kbds: ['meta', 'b'], kbds: ['meta', 'b'],
select() { onSelect() {
console.log('Billing clicked') console.log('Billing clicked')
} }
}, { }, {
label: 'Settings', label: 'Settings',
icon: 'i-heroicons-cog', icon: 'i-heroicons-cog',
kbds: ['?'], kbds: ['?'],
select() { onSelect() {
console.log('Settings clicked') console.log('Settings clicked')
} }
}], [{ }], [{
@@ -44,7 +44,7 @@ const items = [
label: 'Invite by link', label: 'Invite by link',
icon: 'i-heroicons-link', icon: 'i-heroicons-link',
kbds: ['meta', 'i'], kbds: ['meta', 'i'],
select(e: Event) { onSelect(e: Event) {
e?.preventDefault() e?.preventDefault()
console.log('Invite by link clicked') console.log('Invite by link clicked')
} }
@@ -56,21 +56,21 @@ const items = [
icon: 'i-simple-icons-slack', icon: 'i-simple-icons-slack',
to: 'https://slack.com', to: 'https://slack.com',
target: '_blank', target: '_blank',
select(e: Event) { onSelect(e: Event) {
e.preventDefault() e.preventDefault()
console.log('Import from Slack clicked') console.log('Import from Slack clicked')
} }
}, { }, {
label: 'Import from Trello', label: 'Import from Trello',
icon: 'i-simple-icons-trello', icon: 'i-simple-icons-trello',
select(e: Event) { onSelect(e: Event) {
e.preventDefault() e.preventDefault()
console.log('Import from Trello clicked') console.log('Import from Trello clicked')
} }
}, { }, {
label: 'Import from Asana', label: 'Import from Asana',
icon: 'i-simple-icons-asana', icon: 'i-simple-icons-asana',
select(e: Event) { onSelect(e: Event) {
e.preventDefault() e.preventDefault()
console.log('Import from Asana clicked') console.log('Import from Asana clicked')
} }
@@ -80,7 +80,7 @@ const items = [
label: 'New team', label: 'New team',
icon: 'i-heroicons-plus', icon: 'i-heroicons-plus',
kbds: ['meta', 'n'], kbds: ['meta', 'n'],
select() { onSelect() {
console.log('New team clicked') console.log('New team clicked')
} }
}], [{ }], [{
@@ -88,7 +88,7 @@ const items = [
icon: 'i-simple-icons-github', icon: 'i-simple-icons-github',
to: 'https://github.com/nuxt/ui', to: 'https://github.com/nuxt/ui',
target: '_blank', target: '_blank',
select(e: Event) { onSelect(e: Event) {
e.preventDefault() e.preventDefault()
} }
}, { }, {
@@ -108,7 +108,7 @@ const items = [
label: 'Logout', label: 'Logout',
icon: 'i-heroicons-arrow-right-start-on-rectangle', icon: 'i-heroicons-arrow-right-start-on-rectangle',
kbds: ['shift', 'meta', 'q'], kbds: ['shift', 'meta', 'q'],
select() { onSelect() {
console.log('Logout clicked') console.log('Logout clicked')
} }
}] }]

View File

@@ -24,7 +24,7 @@ export interface CommandPaletteItem extends Pick<ComboboxItemProps, 'disabled'>
chip?: ChipProps chip?: ChipProps
kbds?: KbdProps['value'][] | KbdProps[] kbds?: KbdProps['value'][] | KbdProps[]
slot?: string slot?: string
select?(e?: Event): void onSelect?(e?: Event): void
} }
export interface CommandPaletteGroup<T> { export interface CommandPaletteGroup<T> {
@@ -268,10 +268,10 @@ const groups = computed(() => {
<ComboboxItem <ComboboxItem
v-for="(item, index) in group.items" v-for="(item, index) in group.items"
:key="`group-${groupIndex}-${index}`" :key="`group-${groupIndex}-${index}`"
:value="omit(item, ['matches' as any, 'group' as any, 'select', 'labelHtml', 'suffixHtml'])" :value="omit(item, ['matches' as any, 'group' as any, 'onSelect', 'labelHtml', 'suffixHtml'])"
:disabled="item.disabled" :disabled="item.disabled"
:class="ui.item({ class: props.ui?.item })" :class="ui.item({ class: props.ui?.item })"
@select="item.select" @select="item.onSelect"
> >
<slot :name="item.slot || group.slot || 'item'" :item="item" :index="index"> <slot :name="item.slot || group.slot || 'item'" :item="item" :index="index">
<slot :name="item.slot ? `${item.slot}-leading` : group.slot ? `${group.slot}-leading` : `item-leading`" :item="item" :index="index"> <slot :name="item.slot ? `${item.slot}-leading` : group.slot ? `${group.slot}-leading` : `item-leading`" :item="item" :index="index">

View File

@@ -27,7 +27,7 @@ export interface ContextMenuItem extends Omit<LinkProps, 'type' | 'raw' | 'custo
open?: boolean open?: boolean
defaultOpen?: boolean defaultOpen?: boolean
children?: ContextMenuItem[] | ContextMenuItem[][] children?: ContextMenuItem[] | ContextMenuItem[][]
select?(e: Event): void onSelect?(e: Event): void
} }
type ContextMenuVariants = VariantProps<typeof contextMenu> type ContextMenuVariants = VariantProps<typeof contextMenu>

View File

@@ -108,7 +108,7 @@ const groups = computed(() => props.items?.length ? (Array.isArray(props.items[0
</template> </template>
</UContextMenuContent> </UContextMenuContent>
</ContextMenu.Sub> </ContextMenu.Sub>
<ContextMenu.Item v-else as-child :disabled="item.disabled" :text-value="get(item, props.labelKey as string)" @select="item.select"> <ContextMenu.Item v-else as-child :disabled="item.disabled" :text-value="get(item, props.labelKey as string)" @select="item.onSelect">
<ULink v-slot="{ active, ...slotProps }" v-bind="pickLinkProps(item as Omit<ContextMenuItem, 'type'>)" custom> <ULink v-slot="{ active, ...slotProps }" v-bind="pickLinkProps(item as Omit<ContextMenuItem, 'type'>)" custom>
<ULinkBase v-bind="slotProps" :class="ui.item({ class: [uiOverride?.item, item.class], active })"> <ULinkBase v-bind="slotProps" :class="ui.item({ class: [uiOverride?.item, item.class], active })">
<ReuseItemTemplate :item="item" :active="active" :index="index" /> <ReuseItemTemplate :item="item" :active="active" :index="index" />

View File

@@ -27,7 +27,7 @@ export interface DropdownMenuItem extends Omit<LinkProps, 'type' | 'raw' | 'cust
open?: boolean open?: boolean
defaultOpen?: boolean defaultOpen?: boolean
children?: DropdownMenuItem[] | DropdownMenuItem[][] children?: DropdownMenuItem[] | DropdownMenuItem[][]
select?(e: Event): void onSelect?(e: Event): void
} }
type DropdownMenuVariants = VariantProps<typeof dropdownMenu> type DropdownMenuVariants = VariantProps<typeof dropdownMenu>

View File

@@ -115,7 +115,7 @@ const groups = computed(() => props.items?.length ? (Array.isArray(props.items[0
</template> </template>
</UDropdownMenuContent> </UDropdownMenuContent>
</DropdownMenu.Sub> </DropdownMenu.Sub>
<DropdownMenu.Item v-else as-child :disabled="item.disabled" :text-value="get(item, props.labelKey as string)" @select="item.select"> <DropdownMenu.Item v-else as-child :disabled="item.disabled" :text-value="get(item, props.labelKey as string)" @select="item.onSelect">
<ULink v-slot="{ active, ...slotProps }" v-bind="pickLinkProps(item as Omit<DropdownMenuItem, 'type'>)" custom> <ULink v-slot="{ active, ...slotProps }" v-bind="pickLinkProps(item as Omit<DropdownMenuItem, 'type'>)" custom>
<ULinkBase v-bind="slotProps" :class="ui.item({ class: [uiOverride?.item, item.class], active })"> <ULinkBase v-bind="slotProps" :class="ui.item({ class: [uiOverride?.item, item.class], active })">
<ReuseItemTemplate :item="item" :active="active" :index="index" /> <ReuseItemTemplate :item="item" :active="active" :index="index" />

View File

@@ -23,7 +23,7 @@ export interface InputMenuItem extends Pick<ComboboxItemProps, 'disabled'> {
* @defaultValue 'item' * @defaultValue 'item'
*/ */
type?: 'label' | 'separator' | 'item' type?: 'label' | 'separator' | 'item'
select?(e?: Event): void onSelect?(e?: Event): void
} }
type InputMenuVariants = VariantProps<typeof inputMenu> type InputMenuVariants = VariantProps<typeof inputMenu>
@@ -341,7 +341,7 @@ defineExpose({
:class="ui.item({ class: props.ui?.item })" :class="ui.item({ class: props.ui?.item })"
:disabled="item.disabled" :disabled="item.disabled"
:value="valueKey && typeof item === 'object' ? get(item, props.valueKey as string) : item" :value="valueKey && typeof item === 'object' ? get(item, props.valueKey as string) : item"
@select="item.select" @select="item.onSelect"
> >
<slot name="item" :item="(item as T)" :index="index"> <slot name="item" :item="(item as T)" :index="index">
<slot name="item-leading" :item="(item as T)" :index="index"> <slot name="item-leading" :item="(item as T)" :index="index">

View File

@@ -16,7 +16,7 @@ export interface NavigationMenuChildItem extends Omit<LinkProps, 'raw' | 'custom
label: string label: string
description?: string description?: string
icon?: string icon?: string
select?(e: Event): void onSelect?(e: Event): void
} }
export interface NavigationMenuItem extends Omit<LinkProps, 'raw' | 'custom'>, Pick<NavigationMenuItemProps, 'value'> { export interface NavigationMenuItem extends Omit<LinkProps, 'raw' | 'custom'>, Pick<NavigationMenuItemProps, 'value'> {
@@ -27,7 +27,7 @@ export interface NavigationMenuItem extends Omit<LinkProps, 'raw' | 'custom'>, P
trailingIcon?: string trailingIcon?: string
slot?: string slot?: string
children?: NavigationMenuChildItem[] children?: NavigationMenuChildItem[]
select?(e: Event): void onSelect?(e: Event): void
} }
type NavigationMenuVariants = VariantProps<typeof navigationMenu> type NavigationMenuVariants = VariantProps<typeof navigationMenu>
@@ -128,7 +128,7 @@ const lists = computed(() => props.items?.length ? (Array.isArray(props.items[0]
v-bind="item.children?.length ? { disabled: item.disabled } : { active }" v-bind="item.children?.length ? { disabled: item.disabled } : { active }"
as-child as-child
:active="active" :active="active"
@select="item.select" @select="item.onSelect"
> >
<ULinkBase v-bind="slotProps" :class="ui.link({ class: [props.ui?.link, item.class], active, disabled: !!item.disabled })"> <ULinkBase v-bind="slotProps" :class="ui.link({ class: [props.ui?.link, item.class], active, disabled: !!item.disabled })">
<slot :name="item.slot || 'item'" :item="item" :index="index"> <slot :name="item.slot || 'item'" :item="item" :index="index">
@@ -166,7 +166,7 @@ const lists = computed(() => props.items?.length ? (Array.isArray(props.items[0]
<ul :class="ui.childList({ class: props.ui?.childList })"> <ul :class="ui.childList({ class: props.ui?.childList })">
<li v-for="(childItem, childIndex) in item.children" :key="childIndex" :class="ui.childItem({ class: props.ui?.childItem })"> <li v-for="(childItem, childIndex) in item.children" :key="childIndex" :class="ui.childItem({ class: props.ui?.childItem })">
<ULink v-slot="{ active: childActive, ...childSlotProps }" v-bind="pickLinkProps(childItem)" custom> <ULink v-slot="{ active: childActive, ...childSlotProps }" v-bind="pickLinkProps(childItem)" custom>
<NavigationMenuLink as-child :active="childActive" @select="childItem.select"> <NavigationMenuLink as-child :active="childActive" @select="childItem.onSelect">
<ULinkBase v-bind="childSlotProps" :class="ui.childLink({ class: [props.ui?.childLink, childItem.class], active: childActive })"> <ULinkBase v-bind="childSlotProps" :class="ui.childLink({ class: [props.ui?.childLink, childItem.class], active: childActive })">
<UIcon v-if="childItem.icon" :name="childItem.icon" :class="ui.childLinkIcon({ class: props.ui?.childLinkIcon, active: childActive })" /> <UIcon v-if="childItem.icon" :name="childItem.icon" :class="ui.childLinkIcon({ class: props.ui?.childLinkIcon, active: childActive })" />

View File

@@ -22,7 +22,7 @@ export interface SelectMenuItem extends Pick<ComboboxItemProps, 'disabled'> {
* @defaultValue 'item' * @defaultValue 'item'
*/ */
type?: 'label' | 'separator' | 'item' type?: 'label' | 'separator' | 'item'
select?(e?: Event): void onSelect?(e?: Event): void
} }
type SelectMenuVariants = VariantProps<typeof selectMenu> type SelectMenuVariants = VariantProps<typeof selectMenu>
@@ -283,7 +283,7 @@ function onUpdateOpen(value: boolean) {
:class="ui.item({ class: props.ui?.item })" :class="ui.item({ class: props.ui?.item })"
:disabled="item.disabled" :disabled="item.disabled"
:value="valueKey && typeof item === 'object' ? get(item, props.valueKey as string) : item" :value="valueKey && typeof item === 'object' ? get(item, props.valueKey as string) : item"
@select="item.select" @select="item.onSelect"
> >
<slot name="item" :item="(item as T)" :index="index"> <slot name="item" :item="(item as T)" :index="index">
<slot name="item-leading" :item="(item as T)" :index="index"> <slot name="item-leading" :item="(item as T)" :index="index">

View File

@@ -44,7 +44,7 @@ export function extractShortcuts(items: any[] | any[][]) {
items.forEach((item) => { items.forEach((item) => {
if (item.kbds?.length && (item.select || item.click)) { if (item.kbds?.length && (item.select || item.click)) {
const shortcutKey = item.kbds.join('_') const shortcutKey = item.kbds.join('_')
shortcuts[shortcutKey] = item.select || item.click shortcuts[shortcutKey] = item.onSelect || item.onClick
} }
if (item.children) { if (item.children) {
traverse(item.children.flat()) traverse(item.children.flat())

View File

@@ -23,16 +23,10 @@ describe('ContextMenu', () => {
}], }],
[{ [{
label: 'Show Sidebar', label: 'Show Sidebar',
kbds: ['meta', 'S'], kbds: ['meta', 'S']
select() {
console.log('Show Sidebar clicked')
}
}, { }, {
label: 'Show Toolbar', label: 'Show Toolbar',
kbds: ['shift', 'meta', 'D'], kbds: ['shift', 'meta', 'D']
select() {
console.log('Show Toolbar clicked')
}
}, { }, {
label: 'Collapse Pinned Tabs', label: 'Collapse Pinned Tabs',
disabled: true disabled: true
@@ -48,29 +42,17 @@ describe('ContextMenu', () => {
label: 'Developer', label: 'Developer',
children: [[{ children: [[{
label: 'View Source', label: 'View Source',
kbds: ['option', 'meta', 'U'], kbds: ['option', 'meta', 'U']
select() {
console.log('View Source clicked')
}
}, { }, {
label: 'Developer Tools', label: 'Developer Tools',
kbds: ['option', 'meta', 'I'], kbds: ['option', 'meta', 'I']
select() {
console.log('Developer Tools clicked')
}
}], [{ }], [{
label: 'Inspect Elements', label: 'Inspect Elements',
kbds: ['option', 'meta', 'C'], kbds: ['option', 'meta', 'C']
select() {
console.log('Inspect Elements clicked')
}
}], [{ }], [{
label: 'JavaScript Console', label: 'JavaScript Console',
kbds: ['option', 'meta', 'J'], kbds: ['option', 'meta', 'J'],
slot: 'custom', slot: 'custom'
select() {
console.log('JavaScript Console clicked')
}
}]] }]]
}] }]
] ]

View File

@@ -17,25 +17,15 @@ describe('DropdownMenu', () => {
[{ [{
label: 'Profile', label: 'Profile',
icon: 'i-heroicons-user', icon: 'i-heroicons-user',
slot: 'custom', slot: 'custom'
select(e: Event) {
e.preventDefault()
console.log('Profile clicked')
}
}, { }, {
label: 'Billing', label: 'Billing',
icon: 'i-heroicons-credit-card', icon: 'i-heroicons-credit-card',
kbds: ['meta', 'b'], kbds: ['meta', 'b']
select() {
console.log('Billing clicked')
}
}, { }, {
label: 'Settings', label: 'Settings',
icon: 'i-heroicons-cog', icon: 'i-heroicons-cog',
kbds: ['?'], kbds: ['?']
select() {
console.log('Settings clicked')
}
}], [{ }], [{
label: 'Team', label: 'Team',
icon: 'i-heroicons-users' icon: 'i-heroicons-users'
@@ -48,11 +38,7 @@ describe('DropdownMenu', () => {
}, { }, {
label: 'Invite by link', label: 'Invite by link',
icon: 'i-heroicons-link', icon: 'i-heroicons-link',
kbds: ['meta', 'i'], kbds: ['meta', 'i']
select(e: Event) {
e?.preventDefault()
console.log('Invite by link clicked')
}
}], [{ }], [{
label: 'More', label: 'More',
icon: 'i-heroicons-plus-circle', icon: 'i-heroicons-plus-circle',
@@ -60,42 +46,24 @@ describe('DropdownMenu', () => {
label: 'Import from Slack', label: 'Import from Slack',
icon: 'i-simple-icons-slack', icon: 'i-simple-icons-slack',
to: 'https://slack.com', to: 'https://slack.com',
target: '_blank', target: '_blank'
select(e: Event) {
e.preventDefault()
console.log('Import from Slack clicked')
}
}, { }, {
label: 'Import from Trello', label: 'Import from Trello',
icon: 'i-simple-icons-trello', icon: 'i-simple-icons-trello'
select(e: Event) {
e.preventDefault()
console.log('Import from Trello clicked')
}
}, { }, {
label: 'Import from Asana', label: 'Import from Asana',
icon: 'i-simple-icons-asana', icon: 'i-simple-icons-asana'
select(e: Event) {
e.preventDefault()
console.log('Import from Asana clicked')
}
}] }]
}]] }]]
}, { }, {
label: 'New team', label: 'New team',
icon: 'i-heroicons-plus', icon: 'i-heroicons-plus',
kbds: ['meta', 'n'], kbds: ['meta', 'n']
select() {
console.log('New team clicked')
}
}], [{ }], [{
label: 'GitHub', label: 'GitHub',
icon: 'i-simple-icons-github', icon: 'i-simple-icons-github',
to: 'https://github.com/nuxt/ui', to: 'https://github.com/nuxt/ui',
target: '_blank', target: '_blank'
select(e: Event) {
e.preventDefault()
}
}, { }, {
label: 'Support', label: 'Support',
icon: 'i-heroicons-lifebuoy', icon: 'i-heroicons-lifebuoy',
@@ -112,10 +80,7 @@ describe('DropdownMenu', () => {
}], [{ }], [{
label: 'Logout', label: 'Logout',
icon: 'i-heroicons-arrow-right-start-on-rectangle', icon: 'i-heroicons-arrow-right-start-on-rectangle',
kbds: ['shift', 'meta', 'q'], kbds: ['shift', 'meta', 'q']
select() {
console.log('Logout clicked')
}
}] }]
] ]