Skip to content

Commit

Permalink
fix: manually open-close c-datetime-picker because vuetify's automati…
Browse files Browse the repository at this point in the history
…c `activator=parent` binding is flaky in some situations
  • Loading branch information
ascott18 committed Aug 8, 2024
1 parent 2b2264f commit b0a5dbe
Showing 1 changed file with 2 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@keydown.enter="focused = false"
@keydown.escape="focused = false"
@update:model-value="textInputChanged($event, false)"
@click.capture="showPickerMobile($event)"
@click="menu = !menu"
:append-inner-icon="
internalDateKind == 'time'
? 'fa fa-clock cursor-pointer'
Expand All @@ -49,6 +49,7 @@
activator="parent"
content-class="c-datetime-picker__menu"
:close-on-content-click="false"
:open-on-click="false"
min-width="1px"
>
<v-fab
Expand Down Expand Up @@ -233,15 +234,11 @@ const modelValue = defineModel<Date | null | undefined>();
const { inputBindAttrs, modelMeta, valueMeta, valueOwner } =
useMetadataProps(props);
const nativeInput = ref<HTMLInputElement>();
const focused = ref(false);
const error = ref<string[]>([]);
const menu = ref(false);
const internalTextValue = ref<string>();
const hasMobilePicker = /android|iphone/i.test(navigator.userAgent);
const form: any = inject(Symbol.for("vuetify:form"));
const isDisabled = computed(() => props.disabled || form?.isDisabled.value);
Expand Down Expand Up @@ -380,43 +377,6 @@ const showTime = computed(() => {
);
});
function showPickerMobile(event: MouseEvent) {
if (hasMobilePicker) {
showPicker(event);
}
}
function showPicker(event: MouseEvent) {
if (!interactive.value) {
return;
}
// Firefox Desktop only has pickers for date-only inputs.
// It has no time picker, which makes this essentially useless on firefox for those cases.
if (
internalDateKind.value !== "date" &&
/firefox/i.test(navigator.userAgent) &&
!/android|iphone/i.test(navigator.userAgent)
) {
return;
}
if (nativeInput.value?.showPicker) {
nativeInput.value.showPicker();
event.stopPropagation();
event.preventDefault();
// Immediately unfocus the input element,
// because vuetify will have focused it in its own handler.
// On mobile, we don't want the mobile keyboard to flash open for a few milliseconds,
// and on desktop when the native picker is open it intercepts ALL keyboard input,
// so having the text field is deceptive for the user.
(document.activeElement as HTMLElement)?.blur?.();
return true;
}
}
function createDefaultDate() {
const date = new Date();
if (props.dateKind == "date") {
Expand Down

0 comments on commit b0a5dbe

Please sign in to comment.