diff --git a/playground/components/FormElementsExample.vue b/playground/components/FormElementsExample.vue index bd9404ad..26aa0a76 100644 --- a/playground/components/FormElementsExample.vue +++ b/playground/components/FormElementsExample.vue @@ -1,22 +1,7 @@ @@ -79,44 +73,14 @@ function onSubmit (event: FormSubmitEvent) { - - - - - - - - - - - - - - -
- - Submit - -
-
+
+
diff --git a/src/runtime/components/RadioGroup.vue b/src/runtime/components/RadioGroup.vue index 76131837..1f8877ed 100644 --- a/src/runtime/components/RadioGroup.vue +++ b/src/runtime/components/RadioGroup.vue @@ -14,7 +14,7 @@ type RadioGroupVariants = VariantProps export type RadioGroupOption = { label: string value: T - description: string + description?: string } export interface RadioGroupProps extends Omit { @@ -49,15 +49,15 @@ const props = defineProps>() const emits = defineEmits() defineSlots>() -const rootProps = useForwardPropsEmits(reactivePick(props, 'defaultValue', 'orientation', 'disabled', 'loop', 'name', 'required'), emits) +const rootProps = useForwardPropsEmits(reactivePick(props, 'defaultValue', 'orientation', 'loop', 'name', 'required'), emits) -const { emitFormChange, color, name, size, inputId: _inputId } = useFormField>(props) +const { emitFormChange, color, name, size, inputId: _inputId, disabled } = useFormField>(props) const inputId = _inputId.value ?? useId() const ui = computed(() => tv({ extend: radioGroup, slots: props.ui })({ size: size.value, color: color.value, - disabled: props.disabled, + disabled: disabled.value, required: props.required })) @@ -102,6 +102,7 @@ function onUpdate () { v-model="modelValue" v-bind="rootProps" :name="name" + :disabled="disabled" :class="ui.root({ class: props.class })" @update:model-value="onUpdate" > @@ -116,6 +117,7 @@ function onUpdate () { diff --git a/src/runtime/components/Switch.vue b/src/runtime/components/Switch.vue index b4bf8cb8..09d3ec2e 100644 --- a/src/runtime/components/Switch.vue +++ b/src/runtime/components/Switch.vue @@ -13,6 +13,8 @@ const switchTv = tv({ extend: tv(theme), ...(appConfig.ui?.switch || {}) }) type SwitchVariants = VariantProps export interface SwitchProps extends Omit { + id?: string + name?: string color?: SwitchVariants['color'] size?: SwitchVariants['size'] loading?: boolean @@ -30,23 +32,40 @@ export interface SwitchEmits extends SwitchRootEmits {} import { computed } from 'vue' import { SwitchRoot, SwitchThumb, useForwardPropsEmits } from 'radix-vue' import { reactivePick } from '@vueuse/core' -import { useAppConfig } from '#imports' +import { useAppConfig, useFormField } from '#imports' const props = defineProps() const emits = defineEmits() const appConfig = useAppConfig() -const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'defaultChecked', 'checked', 'required', 'name', 'id', 'value'), emits) +const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'defaultChecked', 'checked', 'required', 'value'), emits) + + +const { inputId, emitFormChange, size, color, name, disabled } = useFormField(props) const ui = computed(() => tv({ extend: switchTv, slots: props.ui })({ - color: props.color, - size: props.size, + color: color.value, + size: size.value, loading: props.loading })) + +// 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. +async function onChecked () { + emitFormChange() +}