Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit c948124

Browse files
committed
feat: tabSubmit and openMenuOnFocus (#24)
1 parent 513c4e7 commit c948124

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ interface Vue3DatePicker {
107107
textInput?: boolean;
108108
textInputOptions?: {
109109
enterSubmit?: boolean;
110+
tabSubmit?: boolean;
110111
openMenu?: boolean;
112+
openMenuOnFocus?: boolean;
111113
rangeSeparator?: string;
112114
format?: null;
113115
};

src/Vue3DatePicker/components/DatepickerInput.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
:value="inputValue"
1212
@input="handleInput"
1313
@keydown.enter="handleEnter"
14+
@keydown.tab="handleTab"
15+
@focus="handleFocus"
1416
/>
1517
<span class="dp__input_icon" v-if="$slots['input-icon'] && !hideInputIcon"><slot name="input-icon" /></span>
1618
<CalendarIcon v-if="!$slots['input-icon'] && !hideInputIcon" class="dp__input_icon dp__input_icons" />
@@ -94,6 +96,19 @@
9496
}
9597
};
9698
99+
const handleTab = (): void => {
100+
if (props.textInputOptions?.tabSubmit && isValidDate(parsedDate.value)) {
101+
emit('setInputDate', parsedDate.value, true);
102+
parsedDate.value = null;
103+
}
104+
};
105+
106+
const handleFocus = (): void => {
107+
if (props.textInputOptions?.openMenuOnFocus && !props.isMenuOpen) {
108+
emit('open');
109+
}
110+
};
111+
97112
const handleOpen = () => {
98113
if (props.textInput && props.textInputOptions?.openMenu && !props.isMenuOpen) {
99114
emit('open');

src/Vue3DatePicker/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export interface TimeGridProps {
5757

5858
export interface ITextInputOptions {
5959
enterSubmit: boolean;
60+
tabSubmit: boolean;
6061
openMenu: boolean;
62+
openMenuOnFocus: boolean;
6163
rangeSeparator: string;
6264
format?: null;
6365
}

src/Vue3DatePicker/utils/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export const hoursToAmPmHours = (index: number): number => {
135135
*/
136136
export const getDefaultTextInputOptions = (): ITextInputOptions => ({
137137
enterSubmit: true,
138+
tabSubmit: true,
138139
openMenu: true,
140+
openMenuOnFocus: true,
139141
rangeSeparator: '-',
140142
});
141143

0 commit comments

Comments
 (0)