Skip to content

Commit 265b487

Browse files
committed
feat: Add escClose to text-input options (resolves #1038)
1 parent 9635454 commit 265b487

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export interface VueDatePickerProps {
199199
rangeSeparator?: string;
200200
selectOnFocus?: boolean;
201201
format?: string | string[] | ((value: string) => Date | null);
202+
escClose?: boolean;
202203
};
203204
monthNameFormat?: 'long' | 'short';
204205
startDate?: string | Date;

src/VueDatePicker/components/DatepickerInput.vue

+11-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@
5858
@click="emit('toggle')"
5959
/>
6060
</div>
61-
<span v-if="$slots['clear-icon'] && (alwaysClearable || inputValue && clearable && !disabled && !readonly)" class="dp--clear-btn"
61+
<span
62+
v-if="$slots['clear-icon'] && (alwaysClearable || (inputValue && clearable && !disabled && !readonly))"
63+
class="dp--clear-btn"
6264
><slot name="clear-icon" :clear="onClear"
6365
/></span>
6466
<button
65-
v-if="!$slots['clear-icon'] && (alwaysClearable || clearable && inputValue && !disabled && !readonly)"
67+
v-if="!$slots['clear-icon'] && (alwaysClearable || (clearable && inputValue && !disabled && !readonly))"
6668
:aria-label="defaultedAriaLabels?.clearInput"
6769
class="dp--clear-btn"
6870
type="button"
@@ -290,13 +292,20 @@
290292
emit('clear');
291293
};
292294
295+
const handleEsc = () => {
296+
emit('close');
297+
};
298+
293299
const handleKeyPress = (ev: KeyboardEvent): void => {
294300
if (ev.key === 'Tab') {
295301
handleTab(ev);
296302
}
297303
if (ev.key === 'Enter') {
298304
handleEnter(ev);
299305
}
306+
if (ev.key === 'Escape' && defaultedTextInput.value.escClose) {
307+
handleEsc();
308+
}
300309
if (!defaultedTextInput.value.enabled) {
301310
if (ev.code === 'Tab') return;
302311
ev.preventDefault();

src/VueDatePicker/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface TextInputOptions {
4747
openMenu: string | boolean;
4848
rangeSeparator: string;
4949
selectOnFocus: boolean;
50+
escClose: boolean;
5051
format?: string | string[] | ((value: string) => Date | null);
5152
}
5253

src/VueDatePicker/utils/defaults.ts

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const getDefaultTextInputOptions = (textInput: TextInputProp): TextInputO
123123
openMenu: 'open',
124124
selectOnFocus: false,
125125
rangeSeparator: ' - ',
126+
escClose: true,
126127
};
127128

128129
if (typeof textInput === 'object') {

0 commit comments

Comments
 (0)