From f4b7218f8441357ce0bee3ac74b717efea8aa234 Mon Sep 17 00:00:00 2001 From: Alex Kunin Date: Tue, 12 Mar 2024 18:51:42 +0200 Subject: [PATCH] fix: prevent date inside field from receiving click on focus (fix #16948) --- ui/src/components/date/QDate.js | 7 ++++++- ui/src/composables/private/use-field.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ui/src/components/date/QDate.js b/ui/src/components/date/QDate.js index 4f85eff0cfc..09e54442212 100644 --- a/ui/src/components/date/QDate.js +++ b/ui/src/components/date/QDate.js @@ -1,4 +1,4 @@ -import { h, ref, computed, watch, Transition, nextTick, getCurrentInstance } from 'vue' +import { h, ref, computed, watch, Transition, nextTick, getCurrentInstance, inject } from 'vue' import QBtn from '../btn/QBtn.js' @@ -1442,6 +1442,11 @@ export default createComponent({ setToday, setView, offsetCalendar, setCalendarTo, setEditingRange }) + const qFieldContainer = inject('q-field-container') + if (qFieldContainer) { + qFieldContainer.swallowClick(true) + } + return () => { const content = [ h('div', { diff --git a/ui/src/composables/private/use-field.js b/ui/src/composables/private/use-field.js index cb5c215ddff..9d694770ad2 100644 --- a/ui/src/composables/private/use-field.js +++ b/ui/src/composables/private/use-field.js @@ -1,4 +1,4 @@ -import { h, ref, computed, Transition, nextTick, onActivated, onDeactivated, onBeforeUnmount, onMounted, getCurrentInstance } from 'vue' +import { h, ref, computed, Transition, nextTick, onActivated, onDeactivated, onBeforeUnmount, onMounted, getCurrentInstance, provide } from 'vue' import QIcon from '../../components/icon/QIcon.js' import QSpinner from '../../components/spinner/QSpinner.js' @@ -549,6 +549,10 @@ export default function (state) { // expose public methods Object.assign(proxy, { focus, blur }) + let shouldSwallowClick = false + + provide('q-field-container', { swallowClick (flag) { shouldSwallowClick = flag } }) + return function renderField () { const labelAttrs = state.getControl === void 0 && slots.control === void 0 ? { @@ -565,6 +569,11 @@ export default function (state) { attrs.class ], style: attrs.style, + onClick: function (e) { + if (shouldSwallowClick) { + prevent(e) + } + }, ...labelAttrs }, [ slots.before !== void 0