ember-autofocus-modifier
Your ember component has just been rendered. Have you ever wanted to focus an element in the DOM right after that? Like focusing this lonely input on your page? Or like focusing a full-screen modal's close button?
This package wraps a modifier to autofocus an element in the DOM. It works for inputs and for other elements.
As an alternative to installing this package, you might want to consider using this snippet.
Usage
By default, it will search for the first non-disabled input in the dom node that it has been attached to.
You can specify a custom selector to target other element as the first positional parameter.
If no child is found, then it will try to focus the element itself.
Examples
To set the autofocus to an ember component:
To set the autofocus to a native html element:
To set the autofocus to the first focusable input of an html container:
Here, #input-2
will be focused as input-1
is disabled:
To set the autofocus to something else than an input in a node's children:
Here, the autofocus will be applied to the button
If the autofocus is applied multiple times, the latest element will be auto-focused:
Here, the autofocus will be applied to the button
Installation
yarn add -D ember-autofocus-modifier
or
npm install --save-dev ember-autofocus-modifier
Compatibility
- Ember.js v3.4 or above
- Ember CLI v2.13 or above
- Node.js v10 or above
Contributing
See the Contributing guide for details.
License
This project is licensed under the MIT License.