npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-autofocus-modifier

v7.0.1

Published

Wraps a modifier to autofocus an element in the DOM.

Downloads

16,804

Readme

ember-autofocus-modifier-illustration

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:

<MyComponent {{autofocus}} />

To set the autofocus to a native html element:

<input {{autofocus}} />

To set the autofocus to the first focusable input of an html container:

Here, #input-2 will be focused as input-1 is disabled:

<form {{autofocus}}>
  <input id="input-1" disabled="disabled" />
  <input id="input-2" />
  <button type="submit" />
</form>

To set the autofocus to something else than an input in a node's children:

Here, the autofocus will be applied to the button

<form {{autofocus "button"}}>
  <input />
  <input />
  <button type="submit" />
</form>

If the autofocus is applied multiple times, the latest element will be auto-focused:

Here, the autofocus will be applied to the button

<form>
  <input {{autofocus}} />
  <input {{autofocus}} />
  <button {{autofocus}} type="submit" />
</form>

Installation

yarn add -D ember-autofocus-modifier

or

npm install --save-dev ember-autofocus-modifier

Compatibility

  • Ember.js v3.28 or above
  • Ember CLI v3.28 or above
  • Node.js v18 or above
  • TypeScript v5.0 or above

TypeScript usage

The autofocus helper has proper Glint types, which allow you to get strict type checking in your templates when using TypeScript.

Unless you are using strict mode templates (via first class component templates), you need to import the addon's Glint template registry entries as described in the Using Addons documentation:

// e.g. types/glint.d.ts
import "@glint/environment-ember-loose";
import type AutofocusRegistry from "ember-autofocus-modifier/template-registry";

declare module "@glint/environment-ember-loose/registry" {
  export default interface Registry
    extends AutofocusRegistry /* other addon registries */ {
    // local entries
  }
}

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.