1212</template >
1313
1414<script lang="ts">
15- export const SimpleListValueKey = Symbol (' SimpleListValueKey' ) as InjectionKey <Ref <string | number | boolean | object | symbol | undefined | null >>;
15+ export const SimpleListValueKey = Symbol (' SimpleListValueKey' ) as InjectionKey <WritableComputedRef <string | symbol | null >>;
1616
1717export interface Props extends OUIAProps , /* @vue-ignore */ HTMLAttributes {
1818 /** Form element name */
1919 name? : string ,
20+ modelValue? : string | null ;
2021 required? : boolean ;
2122 /** aria-label for the <ul> element that wraps the SimpleList items. */
2223 ariaLabel? : string ;
@@ -26,7 +27,7 @@ export interface Props extends OUIAProps, /* @vue-ignore */ HTMLAttributes {
2627<script lang="ts" setup>
2728import styles from ' @patternfly/react-styles/css/components/SimpleList/simple-list' ;
2829
29- import { type Component , type InjectionKey , provide , type HTMLAttributes , ref , type Ref } from ' vue' ;
30+ import { type Component , type InjectionKey , provide , type HTMLAttributes , ref , type Ref , computed , type WritableComputedRef , watch } from ' vue' ;
3031import { findChildrenVNodes } from ' ../../util' ;
3132import Wrap from ' ../../helpers/Wrap.vue' ;
3233import { useOUIAProps , type OUIAProps } from ' ../../helpers/ouia' ;
@@ -39,13 +40,32 @@ defineOptions({
3940const props = defineProps <Props >();
4041const ouiaProps = useOUIAProps ({id: props .ouiaId , safe: props .ouiaSafe });
4142
42- /** Value for the selected item */
43- const value = defineModel <string | number | boolean | object | null >({ default: null });
43+ const emit = defineEmits <{
44+ /** Callback for when the model value changes */
45+ (e : ' update:modelValue' , value : string ): void ;
46+ }>();
4447
4548const slots = defineSlots <{
4649 default? : (props ? : Record <never , never >) => any ;
4750}>();
4851
52+ /** Value for the selected item */
53+ const innerValue: Ref <string | symbol | null > = ref (props .modelValue ?? null );
54+
55+ const value = computed ({
56+ get : () => innerValue .value ,
57+ set : (v : string | symbol | null ) => {
58+ innerValue .value = v ;
59+ if (typeof v === ' string' ) {
60+ emit (' update:modelValue' , v );
61+ }
62+ },
63+ });
64+
65+ watch (() => props .modelValue , (v ) => {
66+ innerValue .value = v ?? null ;
67+ });
68+
4969const grouped = ref (false );
5070provide (SimpleListValueKey , value );
5171
0 commit comments