chore: uniformize defineModel placement and emits

This commit is contained in:
Benjamin Canac
2024-04-27 22:16:41 +02:00
parent def5f7c10b
commit ce28e662d6
7 changed files with 21 additions and 22 deletions

View File

@@ -47,6 +47,13 @@ const props = withDefaults(defineProps<RadioGroupProps<T>>(), { orientation: 've
const emits = defineEmits<RadioGroupEmits>()
defineSlots<RadioGroupSlots<T>>()
const modelValue = defineModel<T>({
set(value) {
emits('change', value)
return value
}
})
const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'defaultValue', 'orientation', 'loop', 'required'), emits)
const { emitFormChange, color, name, size, inputId: _inputId, disabled } = useFormField<RadioGroupProps<T>>(props)
@@ -80,13 +87,6 @@ const normalizedOptions = computed(() => {
return props.options.map(normalizeOption)
})
const modelValue = defineModel<T>({
set(value) {
emits('change', value)
return value
}
})
// FIXME: I think there's a race condition between this and the v-model event.
// This must be triggered after the value updates, otherwise the form validates
// the previous value.