Skip to content

Commit 5ace3f8

Browse files
authored
feat(QDrawer/QHeader/QFooter): Prevent getting keyboard focus when hidden (quasarframework#6732)
1 parent b80dfb2 commit 5ace3f8

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

ui/src/components/drawer/QDrawer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export default Vue.extend({
280280
return `q-drawer--${this.side}` +
281281
(this.bordered === true ? ' q-drawer--bordered' : '') +
282282
(this.isDark === true ? ' q-drawer--dark q-dark' : '') +
283+
(this.showing !== true ? ' q-layout--prevent-focus' : '') +
283284
(
284285
this.belowBreakpoint === true
285286
? ' fixed q-drawer--on-top q-drawer--mobile q-drawer--top-padding'
@@ -450,6 +451,7 @@ export default Vue.extend({
450451
this.__applyBackdrop(0)
451452
this.__applyPosition(this.stateDirection * width)
452453
el.classList.remove('q-drawer--delimiter')
454+
el.classList.add('q-layout--prevent-focus')
453455
}
454456

455457
return
@@ -468,6 +470,7 @@ export default Vue.extend({
468470
const el = this.$refs.content
469471
el.classList.add('no-transition')
470472
el.classList.add('q-drawer--delimiter')
473+
el.classList.remove('q-layout--prevent-focus')
471474
}
472475
},
473476

ui/src/components/footer/QFooter.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,20 @@ export default Vue.extend({
101101
return offset > 0 ? offset : 0
102102
},
103103

104+
hidden () {
105+
return this.value !== true || (this.fixed === true && this.revealed !== true)
106+
},
107+
108+
revealOnFocus () {
109+
return this.value === true && this.hidden === true && this.reveal === true
110+
},
111+
104112
classes () {
105-
return (
106-
(this.fixed === true ? 'fixed' : 'absolute') + '-bottom') +
107-
(this.value === true || this.fixed === true ? '' : ' hidden') +
113+
return (this.fixed === true ? 'fixed' : 'absolute') + '-bottom' +
108114
(this.bordered === true ? ' q-footer--bordered' : '') +
109-
(
110-
this.value !== true || (this.fixed === true && this.revealed !== true)
111-
? ' q-footer--hidden'
112-
: ''
113-
)
115+
(this.hidden === true ? ' q-footer--hidden' : '') +
116+
(this.value !== true ? ' q-layout--prevent-focus' : '') +
117+
(this.value !== true && this.fixed !== true ? ' hidden' : '')
114118
},
115119

116120
style () {
@@ -130,12 +134,12 @@ export default Vue.extend({
130134
},
131135

132136
render (h) {
133-
const child = [
137+
const child = mergeSlot([
134138
h(QResizeObserver, {
135139
props: { debounce: 0 },
136140
on: cache(this, 'resize', { resize: this.__onResize })
137141
})
138-
]
142+
], this, 'default')
139143

140144
this.elevated === true && child.push(
141145
h('div', {
@@ -148,10 +152,11 @@ export default Vue.extend({
148152
class: this.classes,
149153
style: this.style,
150154
on: {
155+
focusin: this.__onFocusin,
151156
...this.$listeners,
152157
input: stop
153158
}
154-
}, mergeSlot(child, this, 'default'))
159+
}, child)
155160
},
156161

157162
created () {
@@ -198,6 +203,12 @@ export default Vue.extend({
198203
position - inflexionPosition < 100 ||
199204
this.layout.height - this.containerHeight - position - this.size < 300
200205
))
206+
},
207+
208+
__onFocusin () {
209+
if (this.revealOnFocus === true) {
210+
this.__updateLocal('revealed', true)
211+
}
201212
}
202213
}
203214
})

ui/src/components/header/QHeader.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,19 @@ export default Vue.extend({
8989
return offset > 0 ? offset : 0
9090
},
9191

92+
hidden () {
93+
return this.value !== true || (this.fixed === true && this.revealed !== true)
94+
},
95+
96+
revealOnFocus () {
97+
return this.value === true && this.hidden === true && this.reveal === true
98+
},
99+
92100
classes () {
93-
return (
94-
this.fixed === true ? 'fixed' : 'absolute') + '-top' +
101+
return (this.fixed === true ? 'fixed' : 'absolute') + '-top' +
95102
(this.bordered === true ? ' q-header--bordered' : '') +
96-
(
97-
this.value !== true || (this.fixed === true && this.revealed !== true)
98-
? ' q-header--hidden'
99-
: ''
100-
)
103+
(this.hidden === true ? ' q-header--hidden' : '') +
104+
(this.value !== true ? ' q-layout--prevent-focus' : '')
101105
},
102106

103107
style () {
@@ -135,6 +139,7 @@ export default Vue.extend({
135139
class: this.classes,
136140
style: this.style,
137141
on: {
142+
focusin: this.__onFocusin,
138143
...this.$listeners,
139144
input: stop
140145
}
@@ -173,6 +178,12 @@ export default Vue.extend({
173178
if (this[prop] !== val) {
174179
this[prop] = val
175180
}
181+
},
182+
183+
__onFocusin () {
184+
if (this.revealOnFocus === true) {
185+
this.__updateLocal('revealed', true)
186+
}
176187
}
177188
}
178189
})

ui/src/components/layout/QLayout.sass

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ body.q-ios-padding
155155
.q-page-sticky
156156
transition: transform .12s, left .12s, right .12s, top .12s, bottom .12s !important
157157

158+
body:not(.q-body--layout-animate)
159+
.q-layout--prevent-focus
160+
visibility: hidden
161+
158162
.q-body--drawer-toggle
159163
overflow-x: hidden !important
160164

ui/src/components/layout/QLayout.styl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ body.q-ios-padding
155155
.q-page-sticky
156156
transition: transform .12s, left .12s, right .12s, top .12s, bottom .12s !important
157157

158+
body:not(.q-body--layout-animate)
159+
.q-layout--prevent-focus
160+
visibility: hidden
161+
158162
.q-body--drawer-toggle
159163
overflow-x: hidden !important
160164

0 commit comments

Comments
 (0)