From 037f8fa5c82d6f211d42002bd55eadf133ffa7bf Mon Sep 17 00:00:00 2001 From: Emils Gulbis Date: Wed, 5 Feb 2025 12:45:35 +0200 Subject: [PATCH 1/8] feat(SelectMenu): add clearable icon to reset modelValue --- docs/content/3.components/select-menu.md | 27 ++++ .../app/pages/components/select-menu.vue | 4 + src/runtime/components/SelectMenu.vue | 28 ++++- src/theme/input.ts | 18 ++- test/components/SelectMenu.spec.ts | 3 +- .../__snapshots__/SelectMenu.spec.ts.snap | 119 ++++++++++-------- 6 files changed, 136 insertions(+), 63 deletions(-) diff --git a/docs/content/3.components/select-menu.md b/docs/content/3.components/select-menu.md index 5b94bb32e5..af7080b670 100644 --- a/docs/content/3.components/select-menu.md +++ b/docs/content/3.components/select-menu.md @@ -614,6 +614,33 @@ props: --- :: +### Clearable + +Use the `clearable` prop to add a clear icon and enable `modelValue` clearing. + +::component-code +--- +prettier: true +ignore: + - items + - modelValue + - class +external: + - items + - modelValue +props: + modelValue: 'Backlog' + clearable: true + trailing: false + items: + - Backlog + - Todo + - In Progress + - Done + class: 'w-48' +--- +:: + ## Examples ### With items type diff --git a/playground/app/pages/components/select-menu.vue b/playground/app/pages/components/select-menu.vue index 9820d51fd0..b3dbc16a57 100644 --- a/playground/app/pages/components/select-menu.vue +++ b/playground/app/pages/components/select-menu.vue @@ -12,6 +12,7 @@ const vegetables = ['Aubergine', 'Broccoli', 'Carrot', 'Courgette', 'Leek'] const items = [[{ label: 'Fruits', type: 'label' }, ...fruits], [{ label: 'Vegetables', type: 'label' }, ...vegetables]] const selectedItems = ref([fruits[0]!, vegetables[0]!]) +const selectedItem = ref(fruits[0]!) const statuses = [{ label: 'Backlog', @@ -89,6 +90,8 @@ const { data: users, status } = await useFetch('https://jsonplaceholder.typicode + +
@@ -98,6 +101,7 @@ const { data: users, status } = await useFetch('https://jsonplaceholder.typicode :items="items" placeholder="Search..." :size="size" + clearable class="w-48" />
diff --git a/src/runtime/components/SelectMenu.vue b/src/runtime/components/SelectMenu.vue index bbdeda3335..f9faf852e7 100644 --- a/src/runtime/components/SelectMenu.vue +++ b/src/runtime/components/SelectMenu.vue @@ -45,6 +45,11 @@ export interface SelectMenuProps, I extends M variant?: SelectMenuVariants['variant'] size?: SelectMenuVariants['size'] required?: boolean + /** + * Determines if user can clear the `modelValue` with icon click + * @defaultValue false + */ + clearable?: boolean /** * The icon displayed to open the menu. * @defaultValue appConfig.ui.icons.chevronDown @@ -55,6 +60,11 @@ export interface SelectMenuProps, I extends M * @defaultValue appConfig.ui.icons.check */ selectedIcon?: string + /** + * The icon displayed to clear the value. + * @defaultValue appConfig.ui.icons.close + */ + clearIcon?: string /** * The content of the menu. * @defaultValue { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' } @@ -152,7 +162,8 @@ const props = withDefaults(defineProps>(), { portal: true, searchInput: true, labelKey: 'label' as never, - resetSearchTermOnBlur: true + resetSearchTermOnBlur: true, + clearable: false }) const emits = defineEmits>() const slots = defineSlots>() @@ -200,6 +211,14 @@ function displayValue(value: T | T[]): string { return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item) } +const isEmpty = computed(() => { + if (Array.isArray(props.modelValue)) { + return props.modelValue.length === 0 + } + + return !(props.modelValue) +}) + const groups = computed(() => props.items?.length ? (Array.isArray(props.items[0]) ? props.items : [props.items]) as SelectMenuItem[][] : []) // eslint-disable-next-line vue/no-dupe-keys const items = computed(() => groups.value.flatMap(group => group) as T[]) @@ -244,6 +263,7 @@ function onUpdate(value: any) { if (toRaw(props.modelValue) === value) { return } + console.log('update', value) // @ts-expect-error - 'target' does not exist in type 'EventInit' const event = new Event('change', { target: { value } }) emits('change', event) @@ -276,6 +296,11 @@ function onUpdateOpen(value: boolean) { clearTimeout(timeoutId) } } + +function onClear() { + const newValue = props.multiple ? [] : null + emits('update:modelValue', newValue as SelectModelValue) +} @@ -328,6 +353,7 @@ function onUpdateOpen(value: boolean) { + diff --git a/src/theme/input.ts b/src/theme/input.ts index f1f9a9ffef..99a2de8b77 100644 --- a/src/theme/input.ts +++ b/src/theme/input.ts @@ -10,7 +10,8 @@ export default (options: Required) => ({ leadingAvatar: 'shrink-0', leadingAvatarSize: '', trailing: 'absolute inset-y-0 end-0 flex items-center', - trailingIcon: 'shrink-0 text-[var(--ui-text-dimmed)]' + trailingIcon: 'shrink-0 text-[var(--ui-text-dimmed)]', + clearIcon: 'shrink-0 text-[var(--ui-text-dimmed)]' }, variants: { ...buttonGroupVariantWithRoot, @@ -21,7 +22,8 @@ export default (options: Required) => ({ trailing: 'pe-2', leadingIcon: 'size-4', leadingAvatarSize: '3xs', - trailingIcon: 'size-4' + trailingIcon: 'size-4', + clearIcon: 'size-3' }, sm: { base: 'px-2.5 py-1.5 text-xs gap-1.5', @@ -29,7 +31,8 @@ export default (options: Required) => ({ trailing: 'pe-2.5', leadingIcon: 'size-4', leadingAvatarSize: '3xs', - trailingIcon: 'size-4' + trailingIcon: 'size-4', + clearIcon: 'size-3.5' }, md: { base: 'px-2.5 py-1.5 text-sm gap-1.5', @@ -37,7 +40,8 @@ export default (options: Required) => ({ trailing: 'pe-2.5', leadingIcon: 'size-5', leadingAvatarSize: '2xs', - trailingIcon: 'size-5' + trailingIcon: 'size-5', + clearIcon: 'size-4' }, lg: { base: 'px-3 py-2 text-sm gap-2', @@ -45,7 +49,8 @@ export default (options: Required) => ({ trailing: 'pe-3', leadingIcon: 'size-5', leadingAvatarSize: '2xs', - trailingIcon: 'size-5' + trailingIcon: 'size-5', + clearIcon: 'size-4' }, xl: { base: 'px-3 py-2 text-base gap-2', @@ -53,7 +58,8 @@ export default (options: Required) => ({ trailing: 'pe-3', leadingIcon: 'size-6', leadingAvatarSize: 'xs', - trailingIcon: 'size-6' + trailingIcon: 'size-6', + clearIcon: 'size-4.5' } }, variant: { diff --git a/test/components/SelectMenu.spec.ts b/test/components/SelectMenu.spec.ts index 37ae81956b..342dbf3884 100644 --- a/test/components/SelectMenu.spec.ts +++ b/test/components/SelectMenu.spec.ts @@ -80,7 +80,8 @@ describe('SelectMenu', () => { ['with item slot', { props, slots: { item: () => 'Item slot' } }], ['with item-leading slot', { props, slots: { 'item-leading': () => 'Item leading slot' } }], ['with item-label slot', { props, slots: { 'item-label': () => 'Item label slot' } }], - ['with item-trailing slot', { props, slots: { 'item-trailing': () => 'Item trailing slot' } }] + ['with item-trailing slot', { props, slots: { 'item-trailing': () => 'Item trailing slot' } }], + ['with clearable', { props: { clearable: true } }] // ['with create-item-label slot', { props: { ...props, searchTerm: 'New value', createItem: true }, slots: { 'create-item-label': () => 'Create item slot' } }] ])('renders %s correctly', async (nameOrHtml: string, options: { props?: SelectMenuProps, slots?: Partial> }) => { const html = await ComponentRender(nameOrHtml, options, SelectMenu) diff --git a/test/components/__snapshots__/SelectMenu.spec.ts.snap b/test/components/__snapshots__/SelectMenu.spec.ts.snap index 5b9300ab5a..a7082ebcab 100644 --- a/test/components/__snapshots__/SelectMenu.spec.ts.snap +++ b/test/components/__snapshots__/SelectMenu.spec.ts.snap @@ -2,7 +2,7 @@ exports[`SelectMenu > renders with arrow correctly 1`] = ` " @@ -46,21 +46,21 @@ exports[`SelectMenu > renders with arrow correctly 1`] = ` `; exports[`SelectMenu > renders with avatar and leadingIcon correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with avatar and trailingIcon correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with avatar correctly 1`] = ` -" +" " @@ -68,7 +68,7 @@ exports[`SelectMenu > renders with avatar correctly 1`] = ` exports[`SelectMenu > renders with class correctly 1`] = ` " @@ -112,9 +112,18 @@ exports[`SelectMenu > renders with class correctly 1`] = ` " `; +exports[`SelectMenu > renders with clearable correctly 1`] = ` +" + + +" +`; + exports[`SelectMenu > renders with default slot correctly 1`] = ` " @@ -160,7 +169,7 @@ exports[`SelectMenu > renders with default slot correctly 1`] = ` exports[`SelectMenu > renders with defaultValue correctly 1`] = ` " @@ -206,7 +215,7 @@ exports[`SelectMenu > renders with defaultValue correctly 1`] = ` exports[`SelectMenu > renders with disabled correctly 1`] = ` " @@ -251,7 +260,7 @@ exports[`SelectMenu > renders with disabled correctly 1`] = ` `; exports[`SelectMenu > renders with icon correctly 1`] = ` -" +" " @@ -259,7 +268,7 @@ exports[`SelectMenu > renders with icon correctly 1`] = ` exports[`SelectMenu > renders with id correctly 1`] = ` " @@ -305,7 +314,7 @@ exports[`SelectMenu > renders with id correctly 1`] = ` exports[`SelectMenu > renders with item slot correctly 1`] = ` " @@ -351,7 +360,7 @@ exports[`SelectMenu > renders with item slot correctly 1`] = ` exports[`SelectMenu > renders with item-label slot correctly 1`] = ` " @@ -397,7 +406,7 @@ exports[`SelectMenu > renders with item-label slot correctly 1`] = ` exports[`SelectMenu > renders with item-leading slot correctly 1`] = ` " @@ -443,7 +452,7 @@ exports[`SelectMenu > renders with item-leading slot correctly 1`] = ` exports[`SelectMenu > renders with item-trailing slot correctly 1`] = ` " @@ -489,7 +498,7 @@ exports[`SelectMenu > renders with item-trailing slot correctly 1`] = ` exports[`SelectMenu > renders with items correctly 1`] = ` " @@ -535,7 +544,7 @@ exports[`SelectMenu > renders with items correctly 1`] = ` exports[`SelectMenu > renders with labelKey correctly 1`] = ` " @@ -580,14 +589,14 @@ exports[`SelectMenu > renders with labelKey correctly 1`] = ` `; exports[`SelectMenu > renders with leading and icon correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with leading slot correctly 1`] = ` -" +" @@ -631,28 +640,28 @@ exports[`SelectMenu > renders with leading slot correctly 1`] = ` `; exports[`SelectMenu > renders with leadingIcon correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with loading and avatar correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with loading correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with loading trailing and avatar correctly 1`] = ` -" +" " @@ -660,7 +669,7 @@ exports[`SelectMenu > renders with loading trailing and avatar correctly 1`] = ` exports[`SelectMenu > renders with loading trailing correctly 1`] = ` " @@ -668,7 +677,7 @@ exports[`SelectMenu > renders with loading trailing correctly 1`] = ` `; exports[`SelectMenu > renders with loadingIcon correctly 1`] = ` -" +" " @@ -676,7 +685,7 @@ exports[`SelectMenu > renders with loadingIcon correctly 1`] = ` exports[`SelectMenu > renders with modelValue correctly 1`] = ` " @@ -722,7 +731,7 @@ exports[`SelectMenu > renders with modelValue correctly 1`] = ` exports[`SelectMenu > renders with multiple and modelValue correctly 1`] = ` " @@ -768,7 +777,7 @@ exports[`SelectMenu > renders with multiple and modelValue correctly 1`] = ` exports[`SelectMenu > renders with multiple correctly 1`] = ` " @@ -814,7 +823,7 @@ exports[`SelectMenu > renders with multiple correctly 1`] = ` exports[`SelectMenu > renders with name correctly 1`] = ` " @@ -860,7 +869,7 @@ exports[`SelectMenu > renders with name correctly 1`] = ` exports[`SelectMenu > renders with neutral variant ghost correctly 1`] = ` " @@ -906,7 +915,7 @@ exports[`SelectMenu > renders with neutral variant ghost correctly 1`] = ` exports[`SelectMenu > renders with neutral variant none correctly 1`] = ` " @@ -952,7 +961,7 @@ exports[`SelectMenu > renders with neutral variant none correctly 1`] = ` exports[`SelectMenu > renders with neutral variant outline correctly 1`] = ` " @@ -998,7 +1007,7 @@ exports[`SelectMenu > renders with neutral variant outline correctly 1`] = ` exports[`SelectMenu > renders with neutral variant soft correctly 1`] = ` " @@ -1044,7 +1053,7 @@ exports[`SelectMenu > renders with neutral variant soft correctly 1`] = ` exports[`SelectMenu > renders with neutral variant subtle correctly 1`] = ` " @@ -1090,7 +1099,7 @@ exports[`SelectMenu > renders with neutral variant subtle correctly 1`] = ` exports[`SelectMenu > renders with placeholder correctly 1`] = ` " @@ -1136,7 +1145,7 @@ exports[`SelectMenu > renders with placeholder correctly 1`] = ` exports[`SelectMenu > renders with primary variant ghost correctly 1`] = ` " @@ -1182,7 +1191,7 @@ exports[`SelectMenu > renders with primary variant ghost correctly 1`] = ` exports[`SelectMenu > renders with primary variant none correctly 1`] = ` " @@ -1228,7 +1237,7 @@ exports[`SelectMenu > renders with primary variant none correctly 1`] = ` exports[`SelectMenu > renders with primary variant outline correctly 1`] = ` " @@ -1274,7 +1283,7 @@ exports[`SelectMenu > renders with primary variant outline correctly 1`] = ` exports[`SelectMenu > renders with primary variant soft correctly 1`] = ` " @@ -1320,7 +1329,7 @@ exports[`SelectMenu > renders with primary variant soft correctly 1`] = ` exports[`SelectMenu > renders with primary variant subtle correctly 1`] = ` " @@ -1366,7 +1375,7 @@ exports[`SelectMenu > renders with primary variant subtle correctly 1`] = ` exports[`SelectMenu > renders with required correctly 1`] = ` " @@ -1412,7 +1421,7 @@ exports[`SelectMenu > renders with required correctly 1`] = ` exports[`SelectMenu > renders with searchInput icon correctly 1`] = ` " @@ -1457,7 +1466,7 @@ exports[`SelectMenu > renders with searchInput icon correctly 1`] = ` exports[`SelectMenu > renders with searchInput placeholder correctly 1`] = ` " @@ -1503,7 +1512,7 @@ exports[`SelectMenu > renders with searchInput placeholder correctly 1`] = ` exports[`SelectMenu > renders with selectedIcon correctly 1`] = ` " @@ -1549,7 +1558,7 @@ exports[`SelectMenu > renders with selectedIcon correctly 1`] = ` exports[`SelectMenu > renders with size lg correctly 1`] = ` " @@ -1595,7 +1604,7 @@ exports[`SelectMenu > renders with size lg correctly 1`] = ` exports[`SelectMenu > renders with size md correctly 1`] = ` " @@ -1641,7 +1650,7 @@ exports[`SelectMenu > renders with size md correctly 1`] = ` exports[`SelectMenu > renders with size sm correctly 1`] = ` " @@ -1687,7 +1696,7 @@ exports[`SelectMenu > renders with size sm correctly 1`] = ` exports[`SelectMenu > renders with size xl correctly 1`] = ` " @@ -1733,7 +1742,7 @@ exports[`SelectMenu > renders with size xl correctly 1`] = ` exports[`SelectMenu > renders with size xs correctly 1`] = ` " @@ -1779,7 +1788,7 @@ exports[`SelectMenu > renders with size xs correctly 1`] = ` exports[`SelectMenu > renders with trailing and icon correctly 1`] = ` " @@ -1788,7 +1797,7 @@ exports[`SelectMenu > renders with trailing and icon correctly 1`] = ` exports[`SelectMenu > renders with trailing slot correctly 1`] = ` " @@ -1834,7 +1843,7 @@ exports[`SelectMenu > renders with trailing slot correctly 1`] = ` exports[`SelectMenu > renders with trailingIcon correctly 1`] = ` " @@ -1843,7 +1852,7 @@ exports[`SelectMenu > renders with trailingIcon correctly 1`] = ` exports[`SelectMenu > renders with trailingIcon correctly 2`] = ` " @@ -1889,7 +1898,7 @@ exports[`SelectMenu > renders with trailingIcon correctly 2`] = ` exports[`SelectMenu > renders with ui correctly 1`] = ` " @@ -1935,7 +1944,7 @@ exports[`SelectMenu > renders with ui correctly 1`] = ` exports[`SelectMenu > renders with valueKey correctly 1`] = ` " @@ -1981,7 +1990,7 @@ exports[`SelectMenu > renders with valueKey correctly 1`] = ` exports[`SelectMenu > renders without searchInput correctly 1`] = ` " From 239b745d51d596a9c6002210be39a46edd430b03 Mon Sep 17 00:00:00 2001 From: Emils Gulbis Date: Wed, 5 Feb 2025 12:45:35 +0200 Subject: [PATCH 2/8] feat(SelectMenu): add clearable icon to reset modelValue --- docs/content/3.components/select-menu.md | 27 ++++ .../app/pages/components/select-menu.vue | 4 + src/runtime/components/SelectMenu.vue | 28 ++++- src/theme/select-menu.ts | 22 +++- test/components/SelectMenu.spec.ts | 3 +- .../__snapshots__/SelectMenu.spec.ts.snap | 119 ++++++++++-------- 6 files changed, 145 insertions(+), 58 deletions(-) diff --git a/docs/content/3.components/select-menu.md b/docs/content/3.components/select-menu.md index 5b94bb32e5..af7080b670 100644 --- a/docs/content/3.components/select-menu.md +++ b/docs/content/3.components/select-menu.md @@ -614,6 +614,33 @@ props: --- :: +### Clearable + +Use the `clearable` prop to add a clear icon and enable `modelValue` clearing. + +::component-code +--- +prettier: true +ignore: + - items + - modelValue + - class +external: + - items + - modelValue +props: + modelValue: 'Backlog' + clearable: true + trailing: false + items: + - Backlog + - Todo + - In Progress + - Done + class: 'w-48' +--- +:: + ## Examples ### With items type diff --git a/playground/app/pages/components/select-menu.vue b/playground/app/pages/components/select-menu.vue index 9820d51fd0..b3dbc16a57 100644 --- a/playground/app/pages/components/select-menu.vue +++ b/playground/app/pages/components/select-menu.vue @@ -12,6 +12,7 @@ const vegetables = ['Aubergine', 'Broccoli', 'Carrot', 'Courgette', 'Leek'] const items = [[{ label: 'Fruits', type: 'label' }, ...fruits], [{ label: 'Vegetables', type: 'label' }, ...vegetables]] const selectedItems = ref([fruits[0]!, vegetables[0]!]) +const selectedItem = ref(fruits[0]!) const statuses = [{ label: 'Backlog', @@ -89,6 +90,8 @@ const { data: users, status } = await useFetch('https://jsonplaceholder.typicode + +
@@ -98,6 +101,7 @@ const { data: users, status } = await useFetch('https://jsonplaceholder.typicode :items="items" placeholder="Search..." :size="size" + clearable class="w-48" />
diff --git a/src/runtime/components/SelectMenu.vue b/src/runtime/components/SelectMenu.vue index bbdeda3335..f9faf852e7 100644 --- a/src/runtime/components/SelectMenu.vue +++ b/src/runtime/components/SelectMenu.vue @@ -45,6 +45,11 @@ export interface SelectMenuProps, I extends M variant?: SelectMenuVariants['variant'] size?: SelectMenuVariants['size'] required?: boolean + /** + * Determines if user can clear the `modelValue` with icon click + * @defaultValue false + */ + clearable?: boolean /** * The icon displayed to open the menu. * @defaultValue appConfig.ui.icons.chevronDown @@ -55,6 +60,11 @@ export interface SelectMenuProps, I extends M * @defaultValue appConfig.ui.icons.check */ selectedIcon?: string + /** + * The icon displayed to clear the value. + * @defaultValue appConfig.ui.icons.close + */ + clearIcon?: string /** * The content of the menu. * @defaultValue { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' } @@ -152,7 +162,8 @@ const props = withDefaults(defineProps>(), { portal: true, searchInput: true, labelKey: 'label' as never, - resetSearchTermOnBlur: true + resetSearchTermOnBlur: true, + clearable: false }) const emits = defineEmits>() const slots = defineSlots>() @@ -200,6 +211,14 @@ function displayValue(value: T | T[]): string { return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item) } +const isEmpty = computed(() => { + if (Array.isArray(props.modelValue)) { + return props.modelValue.length === 0 + } + + return !(props.modelValue) +}) + const groups = computed(() => props.items?.length ? (Array.isArray(props.items[0]) ? props.items : [props.items]) as SelectMenuItem[][] : []) // eslint-disable-next-line vue/no-dupe-keys const items = computed(() => groups.value.flatMap(group => group) as T[]) @@ -244,6 +263,7 @@ function onUpdate(value: any) { if (toRaw(props.modelValue) === value) { return } + console.log('update', value) // @ts-expect-error - 'target' does not exist in type 'EventInit' const event = new Event('change', { target: { value } }) emits('change', event) @@ -276,6 +296,11 @@ function onUpdateOpen(value: boolean) { clearTimeout(timeoutId) } } + +function onClear() { + const newValue = props.multiple ? [] : null + emits('update:modelValue', newValue as SelectModelValue) +} @@ -328,6 +353,7 @@ function onUpdateOpen(value: boolean) { + diff --git a/src/theme/select-menu.ts b/src/theme/select-menu.ts index 5443c6160e..c7f2f54145 100644 --- a/src/theme/select-menu.ts +++ b/src/theme/select-menu.ts @@ -5,7 +5,27 @@ import select from './select' export default (options: Required) => { return defu({ slots: { - input: 'border-b border-[var(--ui-border)]' + input: 'border-b border-[var(--ui-border)]', + clearIcon: 'shrink-0 text-[var(--ui-text-dimmed)]' + }, + variants: { + size: { + xs: { + clearIcon: 'size-3' + }, + sm: { + clearIcon: 'size-3.5' + }, + md: { + clearIcon: 'size-4' + }, + lg: { + clearIcon: 'size-4' + }, + xl: { + clearIcon: 'size-4.5' + } + } } }, select(options)) } diff --git a/test/components/SelectMenu.spec.ts b/test/components/SelectMenu.spec.ts index 37ae81956b..342dbf3884 100644 --- a/test/components/SelectMenu.spec.ts +++ b/test/components/SelectMenu.spec.ts @@ -80,7 +80,8 @@ describe('SelectMenu', () => { ['with item slot', { props, slots: { item: () => 'Item slot' } }], ['with item-leading slot', { props, slots: { 'item-leading': () => 'Item leading slot' } }], ['with item-label slot', { props, slots: { 'item-label': () => 'Item label slot' } }], - ['with item-trailing slot', { props, slots: { 'item-trailing': () => 'Item trailing slot' } }] + ['with item-trailing slot', { props, slots: { 'item-trailing': () => 'Item trailing slot' } }], + ['with clearable', { props: { clearable: true } }] // ['with create-item-label slot', { props: { ...props, searchTerm: 'New value', createItem: true }, slots: { 'create-item-label': () => 'Create item slot' } }] ])('renders %s correctly', async (nameOrHtml: string, options: { props?: SelectMenuProps, slots?: Partial> }) => { const html = await ComponentRender(nameOrHtml, options, SelectMenu) diff --git a/test/components/__snapshots__/SelectMenu.spec.ts.snap b/test/components/__snapshots__/SelectMenu.spec.ts.snap index 5b9300ab5a..a7082ebcab 100644 --- a/test/components/__snapshots__/SelectMenu.spec.ts.snap +++ b/test/components/__snapshots__/SelectMenu.spec.ts.snap @@ -2,7 +2,7 @@ exports[`SelectMenu > renders with arrow correctly 1`] = ` " @@ -46,21 +46,21 @@ exports[`SelectMenu > renders with arrow correctly 1`] = ` `; exports[`SelectMenu > renders with avatar and leadingIcon correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with avatar and trailingIcon correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with avatar correctly 1`] = ` -" +" " @@ -68,7 +68,7 @@ exports[`SelectMenu > renders with avatar correctly 1`] = ` exports[`SelectMenu > renders with class correctly 1`] = ` " @@ -112,9 +112,18 @@ exports[`SelectMenu > renders with class correctly 1`] = ` " `; +exports[`SelectMenu > renders with clearable correctly 1`] = ` +" + + +" +`; + exports[`SelectMenu > renders with default slot correctly 1`] = ` " @@ -160,7 +169,7 @@ exports[`SelectMenu > renders with default slot correctly 1`] = ` exports[`SelectMenu > renders with defaultValue correctly 1`] = ` " @@ -206,7 +215,7 @@ exports[`SelectMenu > renders with defaultValue correctly 1`] = ` exports[`SelectMenu > renders with disabled correctly 1`] = ` " @@ -251,7 +260,7 @@ exports[`SelectMenu > renders with disabled correctly 1`] = ` `; exports[`SelectMenu > renders with icon correctly 1`] = ` -" +" " @@ -259,7 +268,7 @@ exports[`SelectMenu > renders with icon correctly 1`] = ` exports[`SelectMenu > renders with id correctly 1`] = ` " @@ -305,7 +314,7 @@ exports[`SelectMenu > renders with id correctly 1`] = ` exports[`SelectMenu > renders with item slot correctly 1`] = ` " @@ -351,7 +360,7 @@ exports[`SelectMenu > renders with item slot correctly 1`] = ` exports[`SelectMenu > renders with item-label slot correctly 1`] = ` " @@ -397,7 +406,7 @@ exports[`SelectMenu > renders with item-label slot correctly 1`] = ` exports[`SelectMenu > renders with item-leading slot correctly 1`] = ` " @@ -443,7 +452,7 @@ exports[`SelectMenu > renders with item-leading slot correctly 1`] = ` exports[`SelectMenu > renders with item-trailing slot correctly 1`] = ` " @@ -489,7 +498,7 @@ exports[`SelectMenu > renders with item-trailing slot correctly 1`] = ` exports[`SelectMenu > renders with items correctly 1`] = ` " @@ -535,7 +544,7 @@ exports[`SelectMenu > renders with items correctly 1`] = ` exports[`SelectMenu > renders with labelKey correctly 1`] = ` " @@ -580,14 +589,14 @@ exports[`SelectMenu > renders with labelKey correctly 1`] = ` `; exports[`SelectMenu > renders with leading and icon correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with leading slot correctly 1`] = ` -" +" @@ -631,28 +640,28 @@ exports[`SelectMenu > renders with leading slot correctly 1`] = ` `; exports[`SelectMenu > renders with leadingIcon correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with loading and avatar correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with loading correctly 1`] = ` -" +" " `; exports[`SelectMenu > renders with loading trailing and avatar correctly 1`] = ` -" +" " @@ -660,7 +669,7 @@ exports[`SelectMenu > renders with loading trailing and avatar correctly 1`] = ` exports[`SelectMenu > renders with loading trailing correctly 1`] = ` " @@ -668,7 +677,7 @@ exports[`SelectMenu > renders with loading trailing correctly 1`] = ` `; exports[`SelectMenu > renders with loadingIcon correctly 1`] = ` -" +" " @@ -676,7 +685,7 @@ exports[`SelectMenu > renders with loadingIcon correctly 1`] = ` exports[`SelectMenu > renders with modelValue correctly 1`] = ` " @@ -722,7 +731,7 @@ exports[`SelectMenu > renders with modelValue correctly 1`] = ` exports[`SelectMenu > renders with multiple and modelValue correctly 1`] = ` " @@ -768,7 +777,7 @@ exports[`SelectMenu > renders with multiple and modelValue correctly 1`] = ` exports[`SelectMenu > renders with multiple correctly 1`] = ` " @@ -814,7 +823,7 @@ exports[`SelectMenu > renders with multiple correctly 1`] = ` exports[`SelectMenu > renders with name correctly 1`] = ` " @@ -860,7 +869,7 @@ exports[`SelectMenu > renders with name correctly 1`] = ` exports[`SelectMenu > renders with neutral variant ghost correctly 1`] = ` " @@ -906,7 +915,7 @@ exports[`SelectMenu > renders with neutral variant ghost correctly 1`] = ` exports[`SelectMenu > renders with neutral variant none correctly 1`] = ` " @@ -952,7 +961,7 @@ exports[`SelectMenu > renders with neutral variant none correctly 1`] = ` exports[`SelectMenu > renders with neutral variant outline correctly 1`] = ` " @@ -998,7 +1007,7 @@ exports[`SelectMenu > renders with neutral variant outline correctly 1`] = ` exports[`SelectMenu > renders with neutral variant soft correctly 1`] = ` " @@ -1044,7 +1053,7 @@ exports[`SelectMenu > renders with neutral variant soft correctly 1`] = ` exports[`SelectMenu > renders with neutral variant subtle correctly 1`] = ` " @@ -1090,7 +1099,7 @@ exports[`SelectMenu > renders with neutral variant subtle correctly 1`] = ` exports[`SelectMenu > renders with placeholder correctly 1`] = ` " @@ -1136,7 +1145,7 @@ exports[`SelectMenu > renders with placeholder correctly 1`] = ` exports[`SelectMenu > renders with primary variant ghost correctly 1`] = ` " @@ -1182,7 +1191,7 @@ exports[`SelectMenu > renders with primary variant ghost correctly 1`] = ` exports[`SelectMenu > renders with primary variant none correctly 1`] = ` " @@ -1228,7 +1237,7 @@ exports[`SelectMenu > renders with primary variant none correctly 1`] = ` exports[`SelectMenu > renders with primary variant outline correctly 1`] = ` " @@ -1274,7 +1283,7 @@ exports[`SelectMenu > renders with primary variant outline correctly 1`] = ` exports[`SelectMenu > renders with primary variant soft correctly 1`] = ` " @@ -1320,7 +1329,7 @@ exports[`SelectMenu > renders with primary variant soft correctly 1`] = ` exports[`SelectMenu > renders with primary variant subtle correctly 1`] = ` " @@ -1366,7 +1375,7 @@ exports[`SelectMenu > renders with primary variant subtle correctly 1`] = ` exports[`SelectMenu > renders with required correctly 1`] = ` " @@ -1412,7 +1421,7 @@ exports[`SelectMenu > renders with required correctly 1`] = ` exports[`SelectMenu > renders with searchInput icon correctly 1`] = ` " @@ -1457,7 +1466,7 @@ exports[`SelectMenu > renders with searchInput icon correctly 1`] = ` exports[`SelectMenu > renders with searchInput placeholder correctly 1`] = ` " @@ -1503,7 +1512,7 @@ exports[`SelectMenu > renders with searchInput placeholder correctly 1`] = ` exports[`SelectMenu > renders with selectedIcon correctly 1`] = ` " @@ -1549,7 +1558,7 @@ exports[`SelectMenu > renders with selectedIcon correctly 1`] = ` exports[`SelectMenu > renders with size lg correctly 1`] = ` " @@ -1595,7 +1604,7 @@ exports[`SelectMenu > renders with size lg correctly 1`] = ` exports[`SelectMenu > renders with size md correctly 1`] = ` " @@ -1641,7 +1650,7 @@ exports[`SelectMenu > renders with size md correctly 1`] = ` exports[`SelectMenu > renders with size sm correctly 1`] = ` " @@ -1687,7 +1696,7 @@ exports[`SelectMenu > renders with size sm correctly 1`] = ` exports[`SelectMenu > renders with size xl correctly 1`] = ` " @@ -1733,7 +1742,7 @@ exports[`SelectMenu > renders with size xl correctly 1`] = ` exports[`SelectMenu > renders with size xs correctly 1`] = ` " @@ -1779,7 +1788,7 @@ exports[`SelectMenu > renders with size xs correctly 1`] = ` exports[`SelectMenu > renders with trailing and icon correctly 1`] = ` " @@ -1788,7 +1797,7 @@ exports[`SelectMenu > renders with trailing and icon correctly 1`] = ` exports[`SelectMenu > renders with trailing slot correctly 1`] = ` " @@ -1834,7 +1843,7 @@ exports[`SelectMenu > renders with trailing slot correctly 1`] = ` exports[`SelectMenu > renders with trailingIcon correctly 1`] = ` " @@ -1843,7 +1852,7 @@ exports[`SelectMenu > renders with trailingIcon correctly 1`] = ` exports[`SelectMenu > renders with trailingIcon correctly 2`] = ` " @@ -1889,7 +1898,7 @@ exports[`SelectMenu > renders with trailingIcon correctly 2`] = ` exports[`SelectMenu > renders with ui correctly 1`] = ` " @@ -1935,7 +1944,7 @@ exports[`SelectMenu > renders with ui correctly 1`] = ` exports[`SelectMenu > renders with valueKey correctly 1`] = ` " @@ -1981,7 +1990,7 @@ exports[`SelectMenu > renders with valueKey correctly 1`] = ` exports[`SelectMenu > renders without searchInput correctly 1`] = ` " From 49e5c8516203c3196372438146db9575c49c4704 Mon Sep 17 00:00:00 2001 From: Emils Gulbis Date: Wed, 5 Feb 2025 13:23:06 +0200 Subject: [PATCH 3/8] refactor: removed clearIcon from theme/input.ts --- src/theme/input.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/theme/input.ts b/src/theme/input.ts index 99a2de8b77..f1f9a9ffef 100644 --- a/src/theme/input.ts +++ b/src/theme/input.ts @@ -10,8 +10,7 @@ export default (options: Required) => ({ leadingAvatar: 'shrink-0', leadingAvatarSize: '', trailing: 'absolute inset-y-0 end-0 flex items-center', - trailingIcon: 'shrink-0 text-[var(--ui-text-dimmed)]', - clearIcon: 'shrink-0 text-[var(--ui-text-dimmed)]' + trailingIcon: 'shrink-0 text-[var(--ui-text-dimmed)]' }, variants: { ...buttonGroupVariantWithRoot, @@ -22,8 +21,7 @@ export default (options: Required) => ({ trailing: 'pe-2', leadingIcon: 'size-4', leadingAvatarSize: '3xs', - trailingIcon: 'size-4', - clearIcon: 'size-3' + trailingIcon: 'size-4' }, sm: { base: 'px-2.5 py-1.5 text-xs gap-1.5', @@ -31,8 +29,7 @@ export default (options: Required) => ({ trailing: 'pe-2.5', leadingIcon: 'size-4', leadingAvatarSize: '3xs', - trailingIcon: 'size-4', - clearIcon: 'size-3.5' + trailingIcon: 'size-4' }, md: { base: 'px-2.5 py-1.5 text-sm gap-1.5', @@ -40,8 +37,7 @@ export default (options: Required) => ({ trailing: 'pe-2.5', leadingIcon: 'size-5', leadingAvatarSize: '2xs', - trailingIcon: 'size-5', - clearIcon: 'size-4' + trailingIcon: 'size-5' }, lg: { base: 'px-3 py-2 text-sm gap-2', @@ -49,8 +45,7 @@ export default (options: Required) => ({ trailing: 'pe-3', leadingIcon: 'size-5', leadingAvatarSize: '2xs', - trailingIcon: 'size-5', - clearIcon: 'size-4' + trailingIcon: 'size-5' }, xl: { base: 'px-3 py-2 text-base gap-2', @@ -58,8 +53,7 @@ export default (options: Required) => ({ trailing: 'pe-3', leadingIcon: 'size-6', leadingAvatarSize: 'xs', - trailingIcon: 'size-6', - clearIcon: 'size-4.5' + trailingIcon: 'size-6' } }, variant: { From 85993cebb4b31a2d7fc6797c9eaa64e882833754 Mon Sep 17 00:00:00 2001 From: Emils Gulbis Date: Wed, 5 Feb 2025 13:24:09 +0200 Subject: [PATCH 4/8] fix: removed console.log from SelectMenu --- src/runtime/components/SelectMenu.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/runtime/components/SelectMenu.vue b/src/runtime/components/SelectMenu.vue index f9faf852e7..66edd06ce7 100644 --- a/src/runtime/components/SelectMenu.vue +++ b/src/runtime/components/SelectMenu.vue @@ -263,7 +263,6 @@ function onUpdate(value: any) { if (toRaw(props.modelValue) === value) { return } - console.log('update', value) // @ts-expect-error - 'target' does not exist in type 'EventInit' const event = new Event('change', { target: { value } }) emits('change', event) From d38db811c3a421de6eefd04565ac866c2d655ddc Mon Sep 17 00:00:00 2001 From: Emils Gulbis Date: Fri, 7 Mar 2025 11:53:54 +0200 Subject: [PATCH 5/8] feat(SelectMenu): snapshot update and select-menu theme file update --- src/theme/select-menu.ts | 22 +---- .../__snapshots__/SelectMenu.spec.ts.snap | 82 +++++++++---------- 2 files changed, 43 insertions(+), 61 deletions(-) diff --git a/src/theme/select-menu.ts b/src/theme/select-menu.ts index c7f2f54145..47af83e667 100644 --- a/src/theme/select-menu.ts +++ b/src/theme/select-menu.ts @@ -5,27 +5,9 @@ import select from './select' export default (options: Required) => { return defu({ slots: { - input: 'border-b border-[var(--ui-border)]', + input: 'border-b border-(--ui-border)', + focusScope: 'flex flex-col min-h-0', clearIcon: 'shrink-0 text-[var(--ui-text-dimmed)]' - }, - variants: { - size: { - xs: { - clearIcon: 'size-3' - }, - sm: { - clearIcon: 'size-3.5' - }, - md: { - clearIcon: 'size-4' - }, - lg: { - clearIcon: 'size-4' - }, - xl: { - clearIcon: 'size-4.5' - } - } } }, select(options)) } diff --git a/test/components/__snapshots__/SelectMenu.spec.ts.snap b/test/components/__snapshots__/SelectMenu.spec.ts.snap index a7082ebcab..e67cf4ee59 100644 --- a/test/components/__snapshots__/SelectMenu.spec.ts.snap +++ b/test/components/__snapshots__/SelectMenu.spec.ts.snap @@ -9,7 +9,7 @@ exports[`SelectMenu > renders with arrow correctly 1`] = `
-
+
@@ -75,7 +75,7 @@ exports[`SelectMenu > renders with class correctly 1`] = `
-
+
@@ -130,7 +130,7 @@ exports[`SelectMenu > renders with default slot correctly 1`] = `
-
+
@@ -176,7 +176,7 @@ exports[`SelectMenu > renders with defaultValue correctly 1`] = `
-
+
@@ -222,7 +222,7 @@ exports[`SelectMenu > renders with disabled correctly 1`] = `
-
+
@@ -275,7 +275,7 @@ exports[`SelectMenu > renders with id correctly 1`] = `
-
+
@@ -321,7 +321,7 @@ exports[`SelectMenu > renders with item slot correctly 1`] = `
-
+
@@ -367,7 +367,7 @@ exports[`SelectMenu > renders with item-label slot correctly 1`] = `
-
+
@@ -413,7 +413,7 @@ exports[`SelectMenu > renders with item-leading slot correctly 1`] = `
-
+
@@ -459,7 +459,7 @@ exports[`SelectMenu > renders with item-trailing slot correctly 1`] = `
-
+
@@ -505,7 +505,7 @@ exports[`SelectMenu > renders with items correctly 1`] = `
-
+
@@ -551,7 +551,7 @@ exports[`SelectMenu > renders with labelKey correctly 1`] = `
-
+
@@ -602,7 +602,7 @@ exports[`SelectMenu > renders with leading slot correctly 1`] = `
-
+
@@ -692,7 +692,7 @@ exports[`SelectMenu > renders with modelValue correctly 1`] = `
-
+
@@ -738,7 +738,7 @@ exports[`SelectMenu > renders with multiple and modelValue correctly 1`] = `
-
+
@@ -784,7 +784,7 @@ exports[`SelectMenu > renders with multiple correctly 1`] = `
-
+
@@ -830,7 +830,7 @@ exports[`SelectMenu > renders with name correctly 1`] = `
-
+
@@ -876,7 +876,7 @@ exports[`SelectMenu > renders with neutral variant ghost correctly 1`] = `
-
+
@@ -922,7 +922,7 @@ exports[`SelectMenu > renders with neutral variant none correctly 1`] = `
-
+
@@ -968,7 +968,7 @@ exports[`SelectMenu > renders with neutral variant outline correctly 1`] = `
-
+
@@ -1014,7 +1014,7 @@ exports[`SelectMenu > renders with neutral variant soft correctly 1`] = `
-
+
@@ -1060,7 +1060,7 @@ exports[`SelectMenu > renders with neutral variant subtle correctly 1`] = `
-
+
@@ -1106,7 +1106,7 @@ exports[`SelectMenu > renders with placeholder correctly 1`] = `
-
+
@@ -1152,7 +1152,7 @@ exports[`SelectMenu > renders with primary variant ghost correctly 1`] = `
-
+
@@ -1198,7 +1198,7 @@ exports[`SelectMenu > renders with primary variant none correctly 1`] = `
-
+
@@ -1244,7 +1244,7 @@ exports[`SelectMenu > renders with primary variant outline correctly 1`] = `
-
+
@@ -1290,7 +1290,7 @@ exports[`SelectMenu > renders with primary variant soft correctly 1`] = `
-
+
@@ -1336,7 +1336,7 @@ exports[`SelectMenu > renders with primary variant subtle correctly 1`] = `
-
+
@@ -1382,7 +1382,7 @@ exports[`SelectMenu > renders with required correctly 1`] = `
-
+
@@ -1428,7 +1428,7 @@ exports[`SelectMenu > renders with searchInput icon correctly 1`] = `
-
+
@@ -1473,7 +1473,7 @@ exports[`SelectMenu > renders with searchInput placeholder correctly 1`] = `
-
+
@@ -1519,7 +1519,7 @@ exports[`SelectMenu > renders with selectedIcon correctly 1`] = `
-
+
@@ -1565,7 +1565,7 @@ exports[`SelectMenu > renders with size lg correctly 1`] = `
-
+
@@ -1611,7 +1611,7 @@ exports[`SelectMenu > renders with size md correctly 1`] = `
-
+
@@ -1657,7 +1657,7 @@ exports[`SelectMenu > renders with size sm correctly 1`] = `
-
+
@@ -1703,7 +1703,7 @@ exports[`SelectMenu > renders with size xl correctly 1`] = `
-
+
@@ -1749,7 +1749,7 @@ exports[`SelectMenu > renders with size xs correctly 1`] = `
-
+
@@ -1804,7 +1804,7 @@ exports[`SelectMenu > renders with trailing slot correctly 1`] = `
-
+
@@ -1859,7 +1859,7 @@ exports[`SelectMenu > renders with trailingIcon correctly 2`] = `
-
+
@@ -1905,7 +1905,7 @@ exports[`SelectMenu > renders with ui correctly 1`] = `
-
+
@@ -1951,7 +1951,7 @@ exports[`SelectMenu > renders with valueKey correctly 1`] = `
-
+
From c1299d77cdf8b2617fc23a75d080d89c11be6d1d Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 23 Apr 2025 11:24:30 +0200 Subject: [PATCH 6/8] up --- .../app/pages/components/select-menu.vue | 6 +++--- src/runtime/components/SelectMenu.vue | 18 +++++++++--------- src/theme/select-menu.ts | 1 - test/components/SelectMenu.spec.ts | 2 +- .../__snapshots__/SelectMenu.spec.ts.snap | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/playground/app/pages/components/select-menu.vue b/playground/app/pages/components/select-menu.vue index a2e4edd501..11007278ef 100644 --- a/playground/app/pages/components/select-menu.vue +++ b/playground/app/pages/components/select-menu.vue @@ -92,8 +92,8 @@ const { data: users, status } = await useFetch('https://jsonplaceholder.typicode - - + +
@@ -103,7 +103,7 @@ const { data: users, status } = await useFetch('https://jsonplaceholder.typicode :items="items" placeholder="Search..." :size="size" - clearable + clear class="w-48" />
diff --git a/src/runtime/components/SelectMenu.vue b/src/runtime/components/SelectMenu.vue index 1d0e9b2419..a0bebde793 100644 --- a/src/runtime/components/SelectMenu.vue +++ b/src/runtime/components/SelectMenu.vue @@ -55,7 +55,12 @@ export interface SelectMenuProps = Array * Determines if user can clear the `modelValue` with icon click * @defaultValue false */ - clearable?: boolean + clear?: boolean + /** + * The icon displayed to clear the value. + * @defaultValue appConfig.ui.icons.close + */ + clearIcon?: string /** * The icon displayed to open the menu. * @defaultValue appConfig.ui.icons.chevronDown @@ -68,11 +73,6 @@ export interface SelectMenuProps = Array * @IconifyIcon */ selectedIcon?: string - /** - * The icon displayed to clear the value. - * @defaultValue appConfig.ui.icons.close - */ - clearIcon?: string /** * The content of the menu. * @defaultValue { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' } @@ -195,7 +195,7 @@ defineOptions({ inheritAttrs: false }) const props = withDefaults(defineProps>(), { portal: true, searchInput: true, - clearable: false, + clear: false, labelKey: 'label' as never, resetSearchTermOnBlur: true, resetSearchTermOnSelect: true @@ -358,7 +358,7 @@ function onSelect(e: Event, item: SelectMenuItem) { function onClear() { const newValue = props.multiple ? [] : null - emits('update:modelValue', newValue as SelectModelValue) + emits('update:modelValue', newValue) } function isSelectItem(item: SelectMenuItem): item is _SelectMenuItem { @@ -417,7 +417,7 @@ function isSelectItem(item: SelectMenuItem): item is _SelectMenuItem { - + diff --git a/src/theme/select-menu.ts b/src/theme/select-menu.ts index b97ef89289..c8fa433186 100644 --- a/src/theme/select-menu.ts +++ b/src/theme/select-menu.ts @@ -7,7 +7,6 @@ export default (options: Required) => { slots: { input: 'border-b border-default', focusScope: 'flex flex-col min-h-0', - clearIcon: 'shrink-0 text-muted', content: (content: string) => [content, 'origin-(--reka-combobox-content-transform-origin) w-(--reka-combobox-trigger-width)'] } }, select(options)) diff --git a/test/components/SelectMenu.spec.ts b/test/components/SelectMenu.spec.ts index 0d9c93a12a..ade58c7032 100644 --- a/test/components/SelectMenu.spec.ts +++ b/test/components/SelectMenu.spec.ts @@ -50,7 +50,7 @@ describe('SelectMenu', () => { ['without searchInput', { props: { ...props, searchInput: false } }], ['with searchInput placeholder', { props: { ...props, searchInput: { placeholder: 'Filter items...' } } }], ['with searchInput icon', { props: { ...props, searchInput: { icon: 'i-lucide-search' } } }], - ['with clearable', { props: { clearable: true } }], + ['with clear', { props: { clear: true } }], ['with disabled', { props: { ...props, disabled: true } }], ['with required', { props: { ...props, required: true } }], ['with icon', { props: { icon: 'i-lucide-search' } }], diff --git a/test/components/__snapshots__/SelectMenu.spec.ts.snap b/test/components/__snapshots__/SelectMenu.spec.ts.snap index 31a1f9f509..6c639794c7 100644 --- a/test/components/__snapshots__/SelectMenu.spec.ts.snap +++ b/test/components/__snapshots__/SelectMenu.spec.ts.snap @@ -164,7 +164,7 @@ exports[`SelectMenu > renders with class correctly 1`] = ` " `; -exports[`SelectMenu > renders with clearable correctly 1`] = ` +exports[`SelectMenu > renders with clear correctly 1`] = ` " From ed53a9b3c36ef7a2a3af6d6546a66d1428e8cf40 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 23 Apr 2025 11:54:57 +0200 Subject: [PATCH 7/8] up --- docs/content/3.components/select-menu.md | 92 +++++++++++++------ .../app/pages/components/select-menu.vue | 4 +- src/runtime/components/SelectMenu.vue | 12 ++- src/theme/select-menu.ts | 1 + 4 files changed, 79 insertions(+), 30 deletions(-) diff --git a/docs/content/3.components/select-menu.md b/docs/content/3.components/select-menu.md index d5d8bbe1c5..f02b39f014 100644 --- a/docs/content/3.components/select-menu.md +++ b/docs/content/3.components/select-menu.md @@ -457,6 +457,71 @@ You can customize this icon globally in your `vite.config.ts` under `ui.icons.ch ::: :: +### Clear :badge{label="Not released" class="align-text-top"} + +Use the `clear` prop to add a clear icon to reset the model value. + +::component-code +--- +prettier: true +ignore: + - items + - modelValue + - class +external: + - items + - modelValue +props: + modelValue: 'Backlog' + clear: true + items: + - Backlog + - Todo + - In Progress + - Done + class: 'w-48' +--- +:: + +### Clear Icon :badge{label="Not released" class="align-text-top"} + +Use the `clear-icon` prop to customize the clear icon. Defaults to `i-lucide-x`. + +::component-code +--- +prettier: true +ignore: + - items + - modelValue + - class +external: + - items + - modelValue +props: + modelValue: 'Backlog' + clear: true + clearIcon: 'i-lucide-trash' + items: + - Backlog + - Todo + - In Progress + - Done + class: 'w-48' +--- +:: + +::framework-only +#nuxt +:::tip{to="/getting-started/icons/nuxt#theme"} +You can customize this icon globally in your `app.config.ts` under `ui.icons.close` key. +::: + +#vue +:::tip{to="/getting-started/icons/vue#theme"} +You can customize this icon globally in your `vite.config.ts` under `ui.icons.close` key. +::: +:: + ### Selected Icon Use the `selected-icon` prop to customize the icon when an item is selected. Defaults to `i-lucide-check`. @@ -615,33 +680,6 @@ props: --- :: -### Clearable - -Use the `clearable` prop to add a clear icon and enable `modelValue` clearing. - -::component-code ---- -prettier: true -ignore: - - items - - modelValue - - class -external: - - items - - modelValue -props: - modelValue: 'Backlog' - clearable: true - trailing: false - items: - - Backlog - - Todo - - In Progress - - Done - class: 'w-48' ---- -:: - ## Examples ### With items type diff --git a/playground/app/pages/components/select-menu.vue b/playground/app/pages/components/select-menu.vue index 11007278ef..4b0d89bb5c 100644 --- a/playground/app/pages/components/select-menu.vue +++ b/playground/app/pages/components/select-menu.vue @@ -92,8 +92,8 @@ const { data: users, status } = await useFetch('https://jsonplaceholder.typicode - - + +
diff --git a/src/runtime/components/SelectMenu.vue b/src/runtime/components/SelectMenu.vue index a0bebde793..65a764157e 100644 --- a/src/runtime/components/SelectMenu.vue +++ b/src/runtime/components/SelectMenu.vue @@ -417,7 +417,17 @@ function isSelectItem(item: SelectMenuItem): item is _SelectMenuItem { - + diff --git a/src/theme/select-menu.ts b/src/theme/select-menu.ts index c8fa433186..0746be8f0a 100644 --- a/src/theme/select-menu.ts +++ b/src/theme/select-menu.ts @@ -7,6 +7,7 @@ export default (options: Required) => { slots: { input: 'border-b border-default', focusScope: 'flex flex-col min-h-0', + clearIcon: ['hover:text-default', options.theme.transitions && 'transition-colors'], content: (content: string) => [content, 'origin-(--reka-combobox-content-transform-origin) w-(--reka-combobox-trigger-width)'] } }, select(options)) From bc064667550806b60147001d3e4f514f7d6ad62f Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 23 Apr 2025 12:03:40 +0200 Subject: [PATCH 8/8] up --- src/runtime/components/SelectMenu.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/components/SelectMenu.vue b/src/runtime/components/SelectMenu.vue index 65a764157e..f0a3078189 100644 --- a/src/runtime/components/SelectMenu.vue +++ b/src/runtime/components/SelectMenu.vue @@ -358,7 +358,7 @@ function onSelect(e: Event, item: SelectMenuItem) { function onClear() { const newValue = props.multiple ? [] : null - emits('update:modelValue', newValue) + emits('update:modelValue', newValue as GetModelValue) } function isSelectItem(item: SelectMenuItem): item is _SelectMenuItem {