Open TuringJest opened 2 years ago
Hi @TuringJest! 👋
It looks like you provided an invalid or unsupported reproduction URL. Do not use any service other than Codepen, jsFiddle, Codesandbox, and GitHub. Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc. Please edit your original post above and provide a valid reproduction URL as explained.
Without a proper reproduction, your issue will have to get closed.
Thank you for your collaboration. 👏
Hello There!
The rendered HTML for a confirm dialog is something like this (simplified version):
<div class="q-dialog">
<button> cancel </button>
<button> ok </button>
</div
which means the cancel
button is rendered as first and then ok
button is rendered.
quasar itself, focues on the ok
button and both buttons has tabindex=0
attribute. from developer.mozilla:
tabindex="0" means that the element should be focusable in sequential keyboard navigation, after any positive tabindex values and its order is defined by the document's source order.
Which means after pressing the tab keyboard when confirm dialog is open, the focus would be returned to the first focusable element on page and skipping cancel
button because there is no other html element after the ok
button, which is the expected behavior.
Again from developer.mozilla:
A positive value means the element should be focusable in sequential keyboard navigation, with its order defined by the value of the number. That is, tabindex="4" is focused before tabindex="5" and tabindex="0", but after tabindex="3". If multiple elements share the same positive tabindex value, their order relative to each other follows their position in the document source. The maximum value for tabindex is 32767. If not specified, it takes the default value 0.
what we can do is setting tabindex
manually on the buttons to enforce tabbing order.
const { useQuasar } = Quasar
const app = Vue.createApp({
setup () {
const $q = useQuasar()
function confirm () {
$q.dialog({
title: 'Confirm',
message: 'Would you like to turn on the wifi?',
cancel: {
tabindex: 1
},
ok:{
tabindex: 2
},
persistent: true
}).onOk(() => {
// console.log('>>>> OK')
}).onOk(() => {
// console.log('>>>> second OK catcher')
}).onCancel(() => {
// console.log('>>>> Cancel')
}).onDismiss(() => {
// console.log('I am triggered on both OK and Cancel')
})
}
return { confirm }
}
})
app.use(Quasar, { config: {} })
app.mount('#q-app')
<div id="q-app" style="min-height: 100vh;">
<q-btn label="Confirm" color="primary" @click="confirm"></q-btn>
</div>
Hope this helps.
Perhaps it is better to focus on the cancel button initially to prevent the accidental confirmation of the operation (something like delete), this is why, I myself always set the initial focus on the cancel
button.
const { useQuasar } = Quasar
const app = Vue.createApp({
setup () {
const $q = useQuasar()
function confirm () {
$q.dialog({
title: 'Confirm',
message: 'Would you like to turn on the wifi?',
cancel: {
autofocus: true
},
persistent: true
}).onOk(() => {
// console.log('>>>> OK')
}).onOk(() => {
// console.log('>>>> second OK catcher')
}).onCancel(() => {
// console.log('>>>> Cancel')
}).onDismiss(() => {
// console.log('I am triggered on both OK and Cancel')
})
}
return { confirm }
}
})
app.use(Quasar, { config: {} })
app.mount('#q-app')
<div id="q-app" style="min-height: 100vh;">
<q-btn label="Confirm" color="primary" @click="confirm"></q-btn>
</div>
What happened?
The cancel button is not accessible by forward tabbing (shift + tab works) on a dialog with only a
cancel
andok
button and no focusable elements in the body.What did you expect to happen?
Hitting
tab
should cycle throughcancel
as well.Reproduction URL
https://quasar.dev/quasar-plugins/dialog#example--basic
How to reproduce?
cancel
andok
buttons)tab
-> The focus will cycle between adressbar and
ok
Flavour
Quasar CLI (@quasar/cli | @quasar/app)
Areas
Components (quasar), Plugins (quasar)
Platforms/Browsers
Chrome
Quasar info output
Relevant log output
No response
Additional context
No response