Skip to content

Commit

Permalink
feat: Add escClose to text-input options (resolves #1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasenkoo committed Dec 28, 2024
1 parent 9635454 commit 265b487
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export interface VueDatePickerProps {
rangeSeparator?: string;
selectOnFocus?: boolean;
format?: string | string[] | ((value: string) => Date | null);
escClose?: boolean;
};
monthNameFormat?: 'long' | 'short';
startDate?: string | Date;
Expand Down
13 changes: 11 additions & 2 deletions src/VueDatePicker/components/DatepickerInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@
@click="emit('toggle')"
/>
</div>
<span v-if="$slots['clear-icon'] && (alwaysClearable || inputValue && clearable && !disabled && !readonly)" class="dp--clear-btn"
<span
v-if="$slots['clear-icon'] && (alwaysClearable || (inputValue && clearable && !disabled && !readonly))"
class="dp--clear-btn"
><slot name="clear-icon" :clear="onClear"
/></span>
<button
v-if="!$slots['clear-icon'] && (alwaysClearable || clearable && inputValue && !disabled && !readonly)"
v-if="!$slots['clear-icon'] && (alwaysClearable || (clearable && inputValue && !disabled && !readonly))"
:aria-label="defaultedAriaLabels?.clearInput"
class="dp--clear-btn"
type="button"
Expand Down Expand Up @@ -290,13 +292,20 @@
emit('clear');
};
const handleEsc = () => {
emit('close');
};
const handleKeyPress = (ev: KeyboardEvent): void => {
if (ev.key === 'Tab') {
handleTab(ev);
}
if (ev.key === 'Enter') {
handleEnter(ev);
}
if (ev.key === 'Escape' && defaultedTextInput.value.escClose) {
handleEsc();
}
if (!defaultedTextInput.value.enabled) {
if (ev.code === 'Tab') return;
ev.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions src/VueDatePicker/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface TextInputOptions {
openMenu: string | boolean;
rangeSeparator: string;
selectOnFocus: boolean;
escClose: boolean;
format?: string | string[] | ((value: string) => Date | null);
}

Expand Down
1 change: 1 addition & 0 deletions src/VueDatePicker/utils/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const getDefaultTextInputOptions = (textInput: TextInputProp): TextInputO
openMenu: 'open',
selectOnFocus: false,
rangeSeparator: ' - ',
escClose: true,
};

if (typeof textInput === 'object') {
Expand Down

0 comments on commit 265b487

Please sign in to comment.