|
9 | 9 | :style="{ '--dp-arrow-left': arrowPos }"
|
10 | 10 | @mouseleave="clearHoverDate"
|
11 | 11 | @click="handleDpMenuClick"
|
12 |
| - @keydown.esc="handleEsc" |
13 |
| - @keydown.left.prevent="handleArrowKey('left')" |
14 |
| - @keydown.up.prevent="handleArrowKey('up')" |
15 |
| - @keydown.down.prevent="handleArrowKey('down')" |
16 |
| - @keydown.right.prevent="handleArrowKey('right')" |
17 | 12 | @keydown="onKeyDown"
|
18 | 13 | >
|
19 | 14 | <div v-if="((disabled || readonly) && defaultedInline.enabled) || loading" :class="disabledReadonlyOverlay">
|
|
55 | 50 | :class="{ 'dp--preset-range-collapsed': collapse }"
|
56 | 51 | :data-test="preset.testId ?? undefined"
|
57 | 52 | @click.prevent="presetDate(preset.value, preset.noTz)"
|
58 |
| - @keydown.enter.prevent="presetDate(preset.value, preset.noTz)" |
59 |
| - @keydown.space.prevent="presetDate(preset.value, preset.noTz)" |
| 53 | + @keydown="checkKeyDown($event, () => presetDate(preset.value, preset.noTz), true)" |
60 | 54 | >
|
61 | 55 | {{ preset.label }}
|
62 | 56 | </button>
|
|
127 | 121 | import ActionRow from '@/components/ActionRow.vue';
|
128 | 122 |
|
129 | 123 | import { mapSlots, useArrowNavigation, useState, useFlow, useDefaults } from '@/composables';
|
130 |
| - import { checkStopPropagation, unrefElement } from '@/utils/util'; |
| 124 | + import { checkKeyDown, checkStopPropagation, unrefElement } from '@/utils/util'; |
131 | 125 | import { AllProps } from '@/props';
|
132 | 126 |
|
133 | 127 | import MonthPicker from '@/components/MonthPicker/MonthPicker.vue';
|
|
138 | 132 |
|
139 | 133 | import type { DynamicClass, MenuView, InternalModuleValue, MenuExposedFn, MonthModel } from '@/interfaces';
|
140 | 134 | import type { PropType } from 'vue';
|
| 135 | + import { ArrowDirection, EventKey } from '@/constants'; |
141 | 136 |
|
142 | 137 | defineOptions({
|
143 | 138 | compatConfig: {
|
|
309 | 304 | }
|
310 | 305 | };
|
311 | 306 |
|
312 |
| - const handleArrowKey = (arrow: 'up' | 'down' | 'left' | 'right'): void => { |
| 307 | + const handleArrowKey = (arrow: ArrowDirection): void => { |
313 | 308 | if (props.arrowNavigation) {
|
314 |
| - if (arrow === 'up') return arrowUp(); |
315 |
| - if (arrow === 'down') return arrowDown(); |
316 |
| - if (arrow === 'left') return arrowLeft(); |
317 |
| - if (arrow === 'right') return arrowRight(); |
318 |
| - } else if (arrow === 'left' || arrow === 'up') { |
319 |
| - callChildFn('handleArrow', 'left', 0, arrow === 'up'); |
| 309 | + if (arrow === ArrowDirection.up) return arrowUp(); |
| 310 | + if (arrow === ArrowDirection.down) return arrowDown(); |
| 311 | + if (arrow === ArrowDirection.left) return arrowLeft(); |
| 312 | + if (arrow === ArrowDirection.right) return arrowRight(); |
| 313 | + } else if (arrow === ArrowDirection.right || arrow === ArrowDirection.up) { |
| 314 | + callChildFn('handleArrow', ArrowDirection.left, 0, arrow === ArrowDirection.up); |
320 | 315 | } else {
|
321 |
| - callChildFn('handleArrow', 'right', 0, arrow === 'down'); |
| 316 | + callChildFn('handleArrow', ArrowDirection.right, 0, arrow === ArrowDirection.down); |
322 | 317 | }
|
323 | 318 | };
|
324 | 319 |
|
325 | 320 | const checkShiftKey = (ev: KeyboardEvent) => {
|
326 | 321 | setShiftKey(ev.shiftKey);
|
327 |
| - if (!props.disableMonthYearSelect && ev.code === 'Tab') { |
| 322 | + if (!props.disableMonthYearSelect && ev.code === EventKey.tab) { |
328 | 323 | if ((ev.target as HTMLElement).classList.contains('dp__menu') && control.value.shiftKeyInMenu) {
|
329 | 324 | ev.preventDefault();
|
330 | 325 | checkStopPropagation(ev, defaultedConfig.value, true);
|
|
373 | 368 | callChildFn('updateMonthYear', instance, value);
|
374 | 369 | };
|
375 | 370 |
|
| 371 | + const onArrowKey = (ev: KeyboardEvent, arrow: ArrowDirection) => { |
| 372 | + ev.preventDefault(); |
| 373 | + handleArrowKey(arrow); |
| 374 | + }; |
| 375 | +
|
376 | 376 | const onKeyDown = (ev: KeyboardEvent) => {
|
377 | 377 | checkShiftKey(ev);
|
378 |
| - if (ev.key === 'Home' || ev.key === 'End') { |
379 |
| - return callChildFn('selectWeekDate', ev.key === 'Home'); |
| 378 | +
|
| 379 | + if (ev.key === EventKey.home || ev.key === EventKey.end) { |
| 380 | + return callChildFn('selectWeekDate', ev.key === EventKey.home); |
380 | 381 | }
|
381 |
| - if (ev.key === 'PageUp' || ev.key === 'PageDown') { |
| 382 | + if (ev.key === EventKey.pageUp || ev.key === EventKey.pageDown) { |
382 | 383 | if (ev.shiftKey) {
|
383 |
| - return callChildFn('changeYear', ev.key === 'PageUp'); |
| 384 | + return callChildFn('changeYear', ev.key === EventKey.pageUp); |
384 | 385 | }
|
385 |
| - return callChildFn('changeMonth', ev.key === 'PageUp'); |
| 386 | + return callChildFn('changeMonth', ev.key === EventKey.pageUp); |
| 387 | + } |
| 388 | +
|
| 389 | + // ev.preventDefault(); |
| 390 | + switch (ev.key) { |
| 391 | + case EventKey.esc: |
| 392 | + return handleEsc(); |
| 393 | + case EventKey.arrowLeft: |
| 394 | + return onArrowKey(ev, ArrowDirection.left); |
| 395 | + case EventKey.arrowRight: |
| 396 | + return onArrowKey(ev, ArrowDirection.right); |
| 397 | + case EventKey.arrowUp: |
| 398 | + return onArrowKey(ev, ArrowDirection.up); |
| 399 | + case EventKey.arrowDown: |
| 400 | + return onArrowKey(ev, ArrowDirection.down); |
| 401 | + default: |
| 402 | + return; |
386 | 403 | }
|
387 | 404 | };
|
388 | 405 |
|
|
0 commit comments