Skip to content

Commit 1413902

Browse files
committed
fix: Double click required on iOS devices when the date has a marker (fixes #904)
1 parent 26a8dfe commit 1413902

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/VueDatePicker/components/DatePicker/DpCalendar.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
tabindex="0"
4747
:data-test="dayVal.value"
4848
@click.prevent="onDateSelect($event, dayVal)"
49+
@touchend="onDateSelect($event, dayVal, false)"
4950
@keydown="checkKeyDown($event, () => $emit('select-date', dayVal))"
5051
@mouseenter="onMouseOver(dayVal, weekInd, dayInd)"
5152
@mouseleave="onMouseLeave(dayVal)"
@@ -116,7 +117,14 @@
116117
import { computed, nextTick, onMounted, ref } from 'vue';
117118
import { getISOWeek, getWeek } from 'date-fns';
118119
119-
import { checkKeyDown, checkStopPropagation, getDayNames, getDefaultMarker, unrefElement } from '@/utils/util';
120+
import {
121+
checkKeyDown,
122+
checkStopPropagation,
123+
getDayNames,
124+
getDefaultMarker,
125+
isIOS,
126+
unrefElement,
127+
} from '@/utils/util';
120128
import { useArrowNavigation, useDefaults } from '@/composables';
121129
import { PickerBaseProps } from '@/props';
122130
import {
@@ -364,7 +372,8 @@
364372
return getWeekNumber(firstCurrentDate);
365373
};
366374
367-
const onDateSelect = (ev: Event, dayVal: ICalendarDay) => {
375+
const onDateSelect = (ev: Event, dayVal: ICalendarDay, isClick = true) => {
376+
if (isClick && isIOS()) return;
368377
if (!defaultedMultiDates.value.enabled) {
369378
checkStopPropagation(ev, defaultedConfig.value);
370379
emit('select-date', dayVal);

src/VueDatePicker/utils/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,12 @@ export const checkKeyDown = (ev: KeyboardEvent, fn: () => any, prevent = false,
310310
}
311311
if (cb) return cb(ev);
312312
};
313+
314+
export const isIOS = () => {
315+
return (
316+
['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].some((platform) =>
317+
navigator.userAgent.includes(platform),
318+
) ||
319+
(navigator.userAgent.includes('Mac') && 'ontouchend' in document)
320+
);
321+
};

0 commit comments

Comments
 (0)