|
84 | 84 | import { computed, PropType, toRef, toRefs, watch, ref, shallowRef, nextTick, Ref, useAttrs, useSlots } from 'vue'
|
85 | 85 | import omit from 'lodash/omit'
|
86 | 86 |
|
87 |
| -import { filterComponentProps, extractComponentProps, extractComponentEmits } from '../../utils/component-options' |
| 87 | +import { filterComponentProps, extractComponentProps, extractComponentEmits, DateRequest } from '../../utils/component-options' |
88 | 88 | import {
|
89 | 89 | useComponentPresetProp,
|
90 | 90 | useClearable, useClearableEmits, useClearableProps,
|
@@ -153,7 +153,7 @@ const props = defineProps({
|
153 | 153 | ariaResetLabel: useTranslationProp('$t:resetDate'),
|
154 | 154 | ariaSelectedDateLabel: useTranslationProp('$t:selectedDate'),
|
155 | 155 |
|
156 |
| - quickDate: { type: Object as PropType<{date: Date | string; key?: string}| boolean>, default: () => {}, required: false }, |
| 156 | + quickDates: { type: Array as PropType<Array<DateRequest>| boolean>, default: () => {}, required: false }, |
157 | 157 | })
|
158 | 158 |
|
159 | 159 | const emit = defineEmits([
|
@@ -274,20 +274,28 @@ const onInputTextChanged = ({ target }: Event) => {
|
274 | 274 | }
|
275 | 275 |
|
276 | 276 | const onKeyDown = (event: KeyboardEvent) => {
|
277 |
| - const defaultKey = 't' |
278 |
| - const quickDate = (props.quickDate as any)?.key ?? defaultKey |
279 |
| - const shouldInput = !!(event.key.toLocaleLowerCase() === quickDate) |
| 277 | + const keyboardKey = event.key.toLocaleLowerCase() |
| 278 | + const isAlpha = !!keyboardKey.match(/^[A-Za-z]$|^$/) |
280 | 279 |
|
281 |
| - if (event.key.match(/^[a-zA-Z]+$/)) { |
| 280 | + if (isAlpha) { |
282 | 281 | event.preventDefault()
|
283 |
| - valueComputed.value = props.clearValue |
284 |
| - } |
285 | 282 |
|
286 |
| - if (shouldInput) { |
287 |
| - if (typeof props.quickDate === 'string') { |
288 |
| - valueComputed.value = parseDateInputValue(new Date().toString()) |
289 |
| - } else { |
290 |
| - valueComputed.value = typeof ((props.quickDate as any).date) === 'string' ? parseDateInputValue((props.quickDate as any).date as string) : parseDateInputValue((props.quickDate as any).date.toString()) |
| 283 | + const defaultKey = 't' |
| 284 | + const today = new Date().toString() |
| 285 | +
|
| 286 | + let shouldInput = false |
| 287 | + let keyProps |
| 288 | + if (Array.isArray(props.quickDates)) { |
| 289 | + keyProps = props.quickDates.length === 1 && !props.quickDates[0]?.key ? props.quickDates[0] : props.quickDates.find(d => d.key?.toLowerCase() === keyboardKey.toLowerCase()) |
| 290 | + if (keyProps) { shouldInput = true } |
| 291 | + } else if (keyboardKey === defaultKey) { shouldInput = true } |
| 292 | +
|
| 293 | + if (shouldInput) { |
| 294 | + if (keyboardKey === defaultKey && !keyProps) { |
| 295 | + valueComputed.value = parseDateInputValue(today) |
| 296 | + } else if (keyProps) { |
| 297 | + valueComputed.value = typeof (keyProps.date) === 'string' ? parseDateInputValue(keyProps.date as string) : parseDateInputValue(keyProps.date.toString()) |
| 298 | + } |
291 | 299 | }
|
292 | 300 | }
|
293 | 301 | }
|
|
0 commit comments