From 55408ca9b1724db4fea4f7ef643d6eac6cc55df8 Mon Sep 17 00:00:00 2001 From: Jin Yi Date: Sun, 31 Aug 2025 13:40:33 +0900 Subject: [PATCH] refactor: improve props handling for MultiSelect and SingleSelect components MultiSelect: - Remove explicit options prop to pass all PrimeVue props via v-bind="$attrs" - Add defineOptions({ inheritAttrs: false }) for controlled attribute inheritance - Extend PrimeVue MultiSelectProps type in Storybook for type safety - Add component comments explaining differences from SingleSelect and prop requirements SingleSelect: - Keep options prop (required for getLabel function to map values to labels) - Add v-bind="$attrs" to maximize PrimeVue API compatibility - Add defineOptions({ inheritAttrs: false }) for controlled attribute inheritance - Add component and function comments explaining why options prop is necessary Common changes: - Keep option-label="name" as custom option template directly references it - Use label prop instead of placeholder - Improve Storybook type definitions to resolve TypeScript compilation errors This refactor allows MultiSelect to flexibly utilize PrimeVue APIs while SingleSelect maintains necessary customizations with type safety. Co-Authored-By: Claude --- src/components/input/MultiSelect.stories.ts | 16 +++++++++++- src/components/input/MultiSelect.vue | 21 +++++++++++---- src/components/input/SingleSelect.stories.ts | 1 + src/components/input/SingleSelect.vue | 27 ++++++++++++++++++-- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/components/input/MultiSelect.stories.ts b/src/components/input/MultiSelect.stories.ts index bc304b990..e4b41d68f 100644 --- a/src/components/input/MultiSelect.stories.ts +++ b/src/components/input/MultiSelect.stories.ts @@ -1,9 +1,23 @@ import type { Meta, StoryObj } from '@storybook/vue3-vite' +import type { MultiSelectProps } from 'primevue/multiselect' import { ref } from 'vue' import MultiSelect from './MultiSelect.vue' -const meta: Meta = { +// Combine our component props with PrimeVue MultiSelect props +// Since we use v-bind="$attrs", all PrimeVue props are available +interface ExtendedProps extends Partial { + // Our custom props + label?: string + showSearchBox?: boolean + showSelectedCount?: boolean + showClearButton?: boolean + searchPlaceholder?: string + // Override modelValue type to match our Option type + modelValue?: Array<{ name: string; value: string }> +} + +const meta: Meta = { title: 'Components/Input/MultiSelect', component: MultiSelect, tags: ['autodocs'], diff --git a/src/components/input/MultiSelect.vue b/src/components/input/MultiSelect.vue index f6c3dd6cd..1dbb53b46 100644 --- a/src/components/input/MultiSelect.vue +++ b/src/components/input/MultiSelect.vue @@ -1,10 +1,18 @@