Skip to content

Commit 5ce8ec8

Browse files
committed
fix(VDateInput): add missing save / cancel events
1 parent 5c3061b commit 5ce8ec8

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

packages/vuetify/src/labs/VDateInput/VDateInput.tsx

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ export const VDateInput = genericComponent<VDateInputSlots>()({
5656
props: makeVDateInputProps(),
5757

5858
emits: {
59+
save: (value: string) => true,
60+
cancel: () => true,
5961
'update:modelValue': (val: string) => true,
6062
},
6163

62-
setup (props, { slots }) {
64+
setup (props, { emit, slots }) {
6365
const { t } = useLocale()
6466
const adapter = useDate()
6567
const { isFocused, focus, blur } = useFocus(props)
@@ -118,11 +120,17 @@ export const VDateInput = genericComponent<VDateInputSlots>()({
118120
menu.value = true
119121
}
120122

121-
function onSave () {
123+
function onCancel () {
124+
emit('cancel')
122125
menu.value = false
123126
}
124127

125-
function onUpdateModel (value: string) {
128+
function onSave (value: string) {
129+
emit('save', value)
130+
menu.value = false
131+
}
132+
133+
function onUpdateDisplayModel (value: string) {
126134
if (value != null) return
127135

128136
model.value = null
@@ -146,7 +154,7 @@ export const VDateInput = genericComponent<VDateInputSlots>()({
146154
onBlur={ blur }
147155
onClick:control={ isInteractive.value ? onClick : undefined }
148156
onClick:prepend={ isInteractive.value ? onClick : undefined }
149-
onUpdate:modelValue={ onUpdateModel }
157+
onUpdate:modelValue={ onUpdateDisplayModel }
150158
>
151159
{{
152160
...slots,
@@ -165,23 +173,30 @@ export const VDateInput = genericComponent<VDateInputSlots>()({
165173
{ ...confirmEditProps }
166174
v-model={ model.value }
167175
onSave={ onSave }
168-
onCancel={ () => menu.value = false }
176+
onCancel={ onCancel }
169177
>
170178
{{
171179
default: ({ actions, model: proxyModel, save, cancel, isPristine }) => {
180+
function onUpdateModel (value: string) {
181+
if (!props.hideActions) {
182+
proxyModel.value = value
183+
} else {
184+
model.value = value
185+
186+
if (!props.multiple) {
187+
menu.value = false
188+
}
189+
}
190+
191+
emit('save', value)
192+
vDateInputRef.value?.blur()
193+
}
194+
172195
return (
173196
<VDatePicker
174197
{ ...datePickerProps }
175198
modelValue={ props.hideActions ? model.value : proxyModel.value }
176-
onUpdate:modelValue={ val => {
177-
if (!props.hideActions) {
178-
proxyModel.value = val
179-
} else {
180-
model.value = val
181-
182-
if (!props.multiple) menu.value = false
183-
}
184-
}}
199+
onUpdate:modelValue={ value => onUpdateModel(value) }
185200
onMousedown={ (e: MouseEvent) => e.preventDefault() }
186201
>
187202
{{

0 commit comments

Comments
 (0)