question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhancement: Add a focus() (and blur()?) method to mdl-textfield

See original GitHub issue

I’m currently battling to make a login form using 2 mdl-textfields and an mdl-button. I’d like the Enter key to move focus to the next text box (e.g. Username to Password), and then from Password to fire the Login button. Getting the keyup events is no problem (@keyup.native="onKeyUp"), but setting focus without resorting to id’s and document.getElementById() is proving tricky. I tried the Vue ref="password" and then using this.$refs.password.$el.focus(), but of course that targets the div which is the parent of the input field, which then ignores the focus request. Or, am I going about this wrong?

If there’s another vmdl component which already does something similar, perhaps now would be a good time to try a pull request. Can you point me at one which does something like this I could look at?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dsl101commented, Dec 6, 2016

I added these methods, which seem to have the desired effect. In v-if / v-else-if sections which generate the actual <input> tag, it appears you can reuse the ‘ref’, so providing you only end up with one focusTarget ref, all is well:

methods: {
  focus () {
    this.$refs.focusTarget.focus()
  },
  focusAndSelect () {
    this.$refs.focusTarget.focus()
    this.$refs.focusTarget.select()
  },
  blur () {
    this.$refs.focusTarget.blur()
  }
},
0reactions
posvacommented, Dec 7, 2016

@dsl101 Cool, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to focus an MDL TextField - material design lite
What is the proper way to focus a material design lite TextField? This works: $("#myTextField").focus();. This does not work: document.
Read more >
What is Focus & Blur in HTML, CSS & JavaScript? - YouTube
In today's video we'll be taking a look at what the terms " focus " and " blur " are in HTML, CSS...
Read more >
Understand Focus And Blur Event - YouTube
Understand Focus And Blur Event - Advanced JavaScript Tutorial Part - 64Learn More From Our Website:-www.dailywebtuition.
Read more >
Focus events - Unity - Manual
For FocusOut and Blur events, it contains the element that gains focus. For FocusIn and Focus events, it contains the element that loses...
Read more >
Unreal Engine 5.1 Release Notes
In this mode, no post-process vector blur is applied, and denoising is applied ... Virtual Camera also now includes support for Enhanced Input...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found