quasar icon indicating copy to clipboard operation
quasar copied to clipboard

Do not work 'autofocus' property of QInput in Dialog.

Open sontis3 opened this issue 8 years ago • 3 comments

Hi. Quasar v0.17.15. https://jsfiddle.net/x6qg4a23/38/ QInput field with 'autofocus' property has no focus.

sontis3 avatar Sep 18 '18 14:09 sontis3

Hi,

autofocus property focuses the field on first render. When used on a Modal and you click to show the Modal, it's already rendered. So call .focus() on it after Modal is shown.

rstoenescu avatar Sep 18 '18 15:09 rstoenescu

Thank you for answer, but call .focus() in @show event of Dialog do not work too. New example here: https://jsfiddle.net/sontis3/x6qg4a23/47/ Focused field is flashed, but has no focus. What are I do wrong?

sontis3 avatar Sep 18 '18 16:09 sontis3

Hi. On show, QDialog does the following:

  1. emit show
  2. if it has prompt or options it focuses the controls
  3. else it focuses the last button

So when you catch @show and try to focus your field you are before steps 2 and 3, and after you focus you lose focus for the button.

The solution is to focus with a timeout:

onShow() {
  this.$nextTick(() => this.$refs.ff1.focus())
},

full sample here: https://jsfiddle.net/9xk43810/

pdanpdan avatar Sep 18 '18 20:09 pdanpdan