dom-autofocus
focus an element when it enters the dom
Last updated 2 years ago by goto-bus-stop .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install dom-autofocus 
SYNC missed versions from official npm registry.

dom-autofocus

focus an element when it enters the dom

Why?

Because the autofocus attribute only works on page load.

This module uses a MutationObserver to call .focus() immediately after the element is mounted.

npm travis standard

Install

npm install dom-autofocus

Usage

dom-autofocus works well with non-virtual DOM diffing libraries like choo:

var autofocus = require('dom-autofocus')
var html = require('choo/html')

module.exports = function view () {
  return html`
    <body>
      Type here:
      ${autofocus(html`
        <input type="text">
      `)}
    </body>
  `
}

API

el = autofocus(el)

Autofocus the element when it enters the DOM. Returns the input el.

License

Apache-2.0

Current Tags

  • 2.0.0                                ...           latest (2 years ago)

3 Versions

  • 2.0.0                                ...           2 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (1)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |