From 7d0e02f57ae5b56efee2b8123858b76ce106e5a7 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Thu, 26 Mar 2026 23:30:34 +0800 Subject: [PATCH] perf(ui): improve the props and customization of Select component --- .../components/form/select/select.story.vue | 94 ++++++++++++++++++- .../form/combobox-select/combobox-select.vue | 10 +- .../src/components/form/combobox/combobox.vue | 17 +++- .../components/form/select/select-option.vue | 2 +- .../ui/src/components/form/select/select.vue | 80 ++++++++++++++-- 5 files changed, 190 insertions(+), 13 deletions(-) diff --git a/packages/stage-ui/src/components/form/select/select.story.vue b/packages/stage-ui/src/components/form/select/select.story.vue index 071c1d96a..aa79ea02b 100644 --- a/packages/stage-ui/src/components/form/select/select.story.vue +++ b/packages/stage-ui/src/components/form/select/select.story.vue @@ -5,6 +5,7 @@ import { ref } from 'vue' const basicValue = ref<'option-1' | 'option-2' | 'option-3' | undefined>('option-1') const groupedValue = ref<'apple' | 'banana' | 'carrot' | 'spinach' | undefined>('banana') const customValue = ref<'apple' | 'banana' | 'carrot' | 'spinach' | undefined>('carrot') +const emptyCustomValue = ref<'apple' | 'banana' | 'carrot' | 'spinach' | undefined>(undefined) const disabledValue = ref<'busy' | 'away' | 'offline' | undefined>('away') const basicOptions = [ @@ -101,7 +102,7 @@ const statusOptions = [

- Custom option value: {{ customValue || 'none' }} + Custom rendered value: {{ customValue || 'none' }}

@@ -158,5 +189,64 @@ const statusOptions = [

+ + +
+ +

+ Empty custom value: {{ emptyCustomValue || 'none' }} +

+
+
diff --git a/packages/ui/src/components/form/combobox-select/combobox-select.vue b/packages/ui/src/components/form/combobox-select/combobox-select.vue index 67b8bb2f9..ade8dfee8 100644 --- a/packages/ui/src/components/form/combobox-select/combobox-select.vue +++ b/packages/ui/src/components/form/combobox-select/combobox-select.vue @@ -9,6 +9,8 @@ const props = defineProps<{ disabled?: boolean title?: string layout?: 'horizontal' | 'vertical' + contentMinWidth?: string | number + contentWidth?: string | number }>() const show = ref(false) @@ -27,5 +29,11 @@ provide('hide', handleHide) diff --git a/packages/ui/src/components/form/combobox/combobox.vue b/packages/ui/src/components/form/combobox/combobox.vue index 83edb8d7d..0f0396e41 100644 --- a/packages/ui/src/components/form/combobox/combobox.vue +++ b/packages/ui/src/components/form/combobox/combobox.vue @@ -20,6 +20,8 @@ import { const props = defineProps<{ options: { groupLabel: string, children?: { label: string, value: T }[] }[] placeholder?: string + contentMinWidth?: string | number + contentWidth?: string | number }>() const modelValue = defineModel({ required: false }) @@ -28,6 +30,14 @@ function toDisplayValue(value: T): string { const option = props.options.flatMap(group => group.children).find(option => option?.value === value) return option ? option.label : props.placeholder || '' } + +function toCssSize(value?: string | number): string | undefined { + if (value == null) { + return undefined + } + + return typeof value === 'number' ? `${value}px` : value +}