diff --git a/playground/app/pages/form.vue b/playground/app/pages/form.vue index 4cf0987c..e4e20c04 100644 --- a/playground/app/pages/form.vue +++ b/playground/app/pages/form.vue @@ -72,14 +72,43 @@ function onSubmit(event: FormSubmitEvent) { - - -
- -
-
+ + + +
+
+

+ Validate on input +

+ +
+
+

+ Validate on change +

+ +
+
+

+ Validate on blur +

+ +
+
+

+ Default +

+ +
+
+

+ Disabled +

+ +
+
diff --git a/src/runtime/components/Checkbox.vue b/src/runtime/components/Checkbox.vue index 717fef75..597ae4e4 100644 --- a/src/runtime/components/Checkbox.vue +++ b/src/runtime/components/Checkbox.vue @@ -41,6 +41,7 @@ export interface CheckboxSlots { export interface CheckboxEmits { (e: 'update:modelValue', payload: boolean): void + (e: 'change', payload: Event): void } @@ -52,14 +53,14 @@ import { useId, useAppConfig, useFormField } from '#imports' const props = defineProps() const slots = defineSlots() -defineEmits() +const emits = defineEmits() const modelValue = defineModel({ default: undefined }) const rootProps = useForwardProps(reactivePick(props, 'required', 'value')) const appConfig = useAppConfig() -const { id: _id, emitFormChange, size, color, name, disabled } = useFormField(props) +const { id: _id, emitFormChange, emitFormInput, size, color, name, disabled } = useFormField(props) const id = _id.value ?? useId() const indeterminate = computed(() => (modelValue.value === undefined && props.indeterminate)) @@ -80,6 +81,13 @@ const ui = computed(() => tv({ extend: checkbox, slots: props.ui })({ disabled: disabled.value, checked: (modelValue.value ?? props.defaultValue) || indeterminate.value })) + +function onUpdate(value: any) { + const event = new Event('change', { target: { value } }) + emits('change', event) + emitFormChange() + emitFormInput() +}