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

Commit ca55825

Browse files
committed
fix: Clear button with stop propagation and multiple open instances
1 parent 96b0c74 commit ca55825

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/Vue3DatePicker/Vue3DatePicker.vue

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@
196196
});
197197
const slots = useSlots();
198198
const isOpen = ref(false);
199-
const valueCleared = ref(false);
200199
const modelValue = toRef(props, 'modelValue');
201200
202201
onMounted(() => {
@@ -314,15 +313,12 @@
314313
315314
const openMenu = (): void => {
316315
if (!props.disabled && !props.readonly) {
317-
if (!valueCleared.value) {
318-
setMenuPosition();
319-
isOpen.value = !isOpen.value;
316+
setMenuPosition();
317+
isOpen.value = !isOpen.value;
320318
321-
if (!isOpen.value) {
322-
clearInternalValues();
323-
}
319+
if (!isOpen.value) {
320+
clearInternalValues();
324321
}
325-
valueCleared.value = false;
326322
parseExternalModelValue(props.modelValue);
327323
}
328324
};
@@ -332,7 +328,6 @@
332328
* for the modelValue and clear internally stored data
333329
*/
334330
const clearValue = (): void => {
335-
valueCleared.value = true;
336331
inputValue.value = '';
337332
clearInternalValues();
338333
emit('update:modelValue', null);

src/Vue3DatePicker/components/DatepickerInput.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@
2929
@keydown.tab="handleTab"
3030
@focus="handleFocus"
3131
/>
32-
<span class="dp__input_icon" v-if="$slots['input-icon'] && !hideInputIcon"><slot name="input-icon" /></span>
33-
<CalendarIcon v-if="!$slots['input-icon'] && !hideInputIcon" class="dp__input_icon dp__input_icons" />
32+
<span class="dp__input_icon" v-if="$slots['input-icon'] && !hideInputIcon" @click="stopPropagation"
33+
><slot name="input-icon"
34+
/></span>
35+
<CalendarIcon
36+
v-if="!$slots['input-icon'] && !hideInputIcon"
37+
class="dp__input_icon dp__input_icons"
38+
@click="stopPropagation"
39+
/>
3440
<span
3541
class="dp__clear_icon"
3642
v-if="$slots['clear-icon'] && clearable && !disabled && !readonly"
@@ -40,7 +46,7 @@
4046
<CancelIcon
4147
v-if="clearable && !$slots['clear-icon'] && inputValue && !disabled && !readonly"
4248
class="dp__clear_icon dp__input_icons"
43-
@click.prevent="onClear"
49+
@click.stop.prevent="onClear"
4450
/>
4551
</div>
4652
</div>
@@ -124,15 +130,18 @@
124130
}
125131
};
126132
127-
const handleOpen = (e: Event) => {
128-
e.stopImmediatePropagation();
133+
const handleOpen = () => {
129134
if (props.textInput && props.textInputOptions?.openMenu && !props.isMenuOpen) {
130135
emit('open');
131136
} else if (!props.textInput) {
132137
emit('open');
133138
}
134139
};
135140
141+
const stopPropagation = (e: Event) => {
142+
e.stopImmediatePropagation();
143+
};
144+
136145
const onClear = () => {
137146
emit('clear');
138147
};

0 commit comments

Comments
 (0)