Skip to content

Commit

Permalink
fix: prevent date inside field from receiving click on focus (fix qua…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkunin committed Mar 12, 2024
1 parent 072482b commit f4b7218
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit f4b7218

Please sign in to comment.