Skip to content

Commit 062dab4

Browse files
committed
fix(QKnob): emit immediately on desktop when starting drag
1 parent 8ef865a commit 062dab4

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

ui/src/components/knob/QKnob.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Vue from 'vue'
33
import { position, stopAndPrevent } from '../../utils/event.js'
44
import { between, normalizeToInterval } from '../../utils/format.js'
55
import { slot } from '../../utils/slot.js'
6+
import { cache } from '../../utils/vm.js'
67

78
import QCircularProgress from '../circular-progress/QCircularProgress.js'
89
import TouchPan from '../../directives/TouchPan.js'
@@ -84,21 +85,36 @@ export default Vue.extend({
8485

8586
computedStep () {
8687
return this.step === 0 ? 1 : this.step
88+
},
89+
90+
events () {
91+
return this.$q.platform.is.mobile === true
92+
? { click: this.__click }
93+
: {
94+
mousedown: this.__activate,
95+
click: this.__click,
96+
keydown: this.__keydown,
97+
keyup: this.__keyup
98+
}
8799
}
88100
},
89101

90102
methods: {
103+
__updateCenterPosition () {
104+
const { top, left, width, height } = this.$el.getBoundingClientRect()
105+
this.centerPosition = {
106+
top: top + height / 2,
107+
left: left + width / 2
108+
}
109+
},
110+
91111
__pan (event) {
92112
if (event.isFinal) {
93113
this.__updatePosition(event.evt, true)
94114
this.dragging = false
95115
}
96116
else if (event.isFirst) {
97-
const { top, left, width, height } = this.$el.getBoundingClientRect()
98-
this.centerPosition = {
99-
top: top + height / 2,
100-
left: left + width / 2
101-
}
117+
this.__updateCenterPosition()
102118
this.dragging = true
103119
this.__updatePosition(event.evt)
104120
}
@@ -108,11 +124,7 @@ export default Vue.extend({
108124
},
109125

110126
__click (evt) {
111-
const { top, left, width, height } = this.$el.getBoundingClientRect()
112-
this.centerPosition = {
113-
top: top + height / 2,
114-
left: left + width / 2
115-
}
127+
this.__updateCenterPosition()
116128
this.__updatePosition(evt, true)
117129
},
118130

@@ -142,6 +154,12 @@ export default Vue.extend({
142154
}
143155
},
144156

157+
__activate (evt) {
158+
this.__updateCenterPosition()
159+
this.__updatePosition(evt)
160+
this.__updateValue()
161+
},
162+
145163
__updatePosition (evt, change) {
146164
const
147165
center = this.centerPosition,
@@ -213,20 +231,16 @@ export default Vue.extend({
213231

214232
if (this.editable === true) {
215233
data.attrs = { tabindex: this.tabindex }
216-
data.on = {
217-
click: this.__click,
218-
keydown: this.__keydown,
219-
keyup: this.__keyup
220-
}
221-
data.directives = [{
234+
data.on = this.events
235+
data.directives = cache(this, 'dir', [{
222236
name: 'touch-pan',
223237
value: this.__pan,
224238
modifiers: {
225239
prevent: true,
226240
stop: true,
227241
mouse: true
228242
}
229-
}]
243+
}])
230244
}
231245

232246
return h(QCircularProgress, data, slot(this, 'default'))

0 commit comments

Comments
 (0)