Skip to content

Commit 64056a3

Browse files
committed
feat(FormSelect): component is generic and accepts/returns string or string[] depending on the multiple prop
1 parent 25beabd commit 64056a3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/core/src/components/FormSelect/FormSelect.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
v-bind="$attrs"
1717
v-model="value"
1818
:disabled="disabled || undefined"
19+
:multiple="multiple || undefined"
1920
>
2021
<slot />
2122
</select>
@@ -31,7 +32,8 @@
3132
<script lang="ts">
3233
export const FormSelectOptionsKey = Symbol("FormSelectOptionsKey") as ChildrenTrackerInjectionKey<InstanceType<typeof PfFormSelectOption>>;
3334
34-
export interface Props extends OUIAProps, /* @vue-ignore */ Omit<SelectHTMLAttributes, 'value'> {
35+
export interface Props<M extends boolean = false> extends OUIAProps, /* @vue-ignore */ Omit<SelectHTMLAttributes, 'value'> {
36+
multiple?: M;
3537
disabled?: boolean;
3638
3739
/**
@@ -44,7 +46,7 @@ export interface Props extends OUIAProps, /* @vue-ignore */ Omit<SelectHTMLAttri
4446
}
4547
</script>
4648

47-
<script lang="ts" setup>
49+
<script lang="ts" setup generic="M extends boolean = false">
4850
import styles from '@patternfly/react-styles/css/components/FormControl/form-control';
4951
import { provideChildrenTracker, type ChildrenTrackerInjectionKey, useChildrenTracker } from '../../use';
5052
import type PfFormSelectOption from './FormSelectOption.vue';
@@ -59,11 +61,15 @@ defineOptions({
5961
inheritAttrs: false,
6062
});
6163
62-
const props = defineProps<Props>();
64+
const props = defineProps<Props<M>>();
6365
const ouiaProps = useOUIAProps({id: props.ouiaId, safe: props.ouiaSafe});
6466
6567
const value = defineModel<string | string[] | null>();
6668
69+
defineEmits<{
70+
(name: 'update:modelValue', value: M extends true ? string[] : string): void;
71+
}>();
72+
6773
defineSlots<{
6874
default?: (props?: Record<never, never>) => any;
6975
}>();

0 commit comments

Comments
 (0)