Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

dom-autofocus

2.0.0 • Public • Published

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

Install

npm i dom-autofocus

DownloadsWeekly Downloads

6

Version

2.0.0

License

Apache-2.0

Unpacked Size

4.47 kB

Total Files

8

Last publish

Collaborators

  • avatar