Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent date inside field from receiving click on focus (fix #16948) #16992

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ui/src/components/date/QDate.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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', {
Expand Down
11 changes: 10 additions & 1 deletion ui/src/composables/private/use-field.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
? {
Expand All @@ -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
Expand Down