Skip to content

Commit 9af4622

Browse files
pdanpdanrstoenescu
authored andcommitted
fix(QField): Set focused status on fields with autoselect from SSR (quasarframework#5796)
1 parent 7671f75 commit 9af4622

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

ui/src/components/dialog-plugin/DialogPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ export default Vue.extend({
161161
if (this.cancel) {
162162
child.push(h(QBtn, {
163163
props: this.cancelProps,
164-
attrs: { 'data-autofocus': this.focus === 'cancel' && !this.hasForm },
164+
attrs: { autofocus: this.focus === 'cancel' && !this.hasForm },
165165
on: cache(this, 'cancel', { click: this.onCancel })
166166
}))
167167
}
168168
if (this.ok) {
169169
child.push(h(QBtn, {
170170
props: this.okProps,
171-
attrs: { 'data-autofocus': this.focus === 'ok' && !this.hasForm },
171+
attrs: { autofocus: this.focus === 'ok' && !this.hasForm },
172172
on: cache(this, 'ok', { click: this.onOk })
173173
}))
174174
}

ui/src/components/dialog/QDialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export default Vue.extend({
134134
return
135135
}
136136

137-
node = node.querySelector('[autofocus], [data-autofocus]') || node
137+
node = node.querySelector('[autofocus]') || node
138138
node.focus()
139139
},
140140

ui/src/components/field/QField.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ export default Vue.extend({
219219
const el = document.activeElement
220220
let target = this.$refs.target
221221
// IE can have null document.activeElement
222-
if (target !== void 0 && (el === null || el.id !== this.targetUid)) {
222+
if (el !== null && el.id === this.targetUid) {
223+
if (this.editable === true && this.focused === false) {
224+
this.focused = true
225+
this.$emit('focus', { type: 'focusin', target: el })
226+
}
227+
}
228+
else if (target !== void 0) {
223229
target.hasAttribute('tabindex') === true || (target = target.querySelector('[tabindex]'))
224230
target !== null && target !== el && target.focus()
225231
}
@@ -315,7 +321,7 @@ export default Vue.extend({
315321
staticClass: 'q-field__native row',
316322
attrs: {
317323
...this.$attrs,
318-
'data-autofocus': this.autofocus
324+
autofocus: this.autofocus
319325
}
320326
}, this.$scopedSlots.control(this.controlSlotScope))
321327
)

ui/src/components/form/QForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export default Vue.extend({
129129
},
130130

131131
focus () {
132-
const target = this.$el.querySelector('[autofocus], [data-autofocus]') ||
132+
const target = this.$el.querySelector('[autofocus]') ||
133133
[].find.call(this.$el.querySelectorAll('[tabindex]'), el => el.tabIndex > -1)
134134

135135
target !== null && target !== void 0 && target.focus()

ui/src/components/input/QInput.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ export default Vue.extend({
9292

9393
methods: {
9494
focus () {
95-
const el = document.activeElement
96-
if (
97-
this.$refs.input !== void 0 &&
98-
this.$refs.input !== el &&
99-
// IE can have null document.activeElement
100-
(el === null || el.id !== this.targetUid)
101-
) {
102-
this.$refs.input.focus()
95+
const
96+
el = document.activeElement,
97+
target = this.$refs.input
98+
// IE can have null document.activeElement
99+
if (el !== null && el.id === this.targetUid) {
100+
if (this.editable === true && this.focused === false) {
101+
this.focused = true
102+
this.$emit('focus', { type: 'focusin', target: el })
103+
}
104+
}
105+
else if (target !== void 0) {
106+
target.focus()
103107
}
104108
},
105109

@@ -234,7 +238,7 @@ export default Vue.extend({
234238

235239
const attrs = {
236240
tabindex: 0,
237-
'data-autofocus': this.autofocus,
241+
autofocus: this.autofocus,
238242
rows: this.type === 'textarea' ? 6 : void 0,
239243
'aria-label': this.label,
240244
...this.$attrs,

ui/src/components/menu/QMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default Vue.extend({
100100
: void 0
101101

102102
if (node !== void 0 && node.contains(document.activeElement) !== true) {
103-
node = node.querySelector('[autofocus], [data-autofocus]') || node
103+
node = node.querySelector('[autofocus]') || node
104104
node.focus()
105105
}
106106
},

ui/src/components/select/QSelect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ export default Vue.extend({
815815
type: 'search',
816816
...this.$attrs,
817817
tabindex: this.tabindex,
818-
'data-autofocus': fromDialog === true ? false : this.autofocus,
818+
autofocus: fromDialog === true ? false : this.autofocus,
819819
id: this.targetUid,
820820
disabled: this.disable === true,
821821
readonly: this.readonly === true

0 commit comments

Comments
 (0)