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

react-controlled-focus

v0.1.5

Published

React component for declarative focus

Downloads

11

Readme

React Controlled Focus

Build Status npm version js-standard-style

One of the biggest advantages of using React is having the possibility of a completely declarative UI, which is amazing until you run into trying to controll focus.

This is an attempt at managing focus the same way controled components handle value.

The biggest difference between focus and value is that focus is not actually a property of the input itself, but rather the document, in the form of the document.activeElement. This library approaches the problem by moving the focus management outside of the individual elements up to a <ControlledFocus> top level component.

Open the demo page to see it in action.

WARNING: The API is nowhere near 1.0 stability and it is pretty much an experiment at this point. Appretiate any feedback if I'm doing something that doesn't make sense.

Usage

Install the package:

npm intall --save react-controlled-focus

The API itself is very simple, wrap the entire application arround a <ControlledFocus>, set up which element should have the focus via the activeElement and handle changes in focus via the onFocus callback:

<ControlledFocus activeElement='input-1' onFocus={}>
  // children components that will have the focus under-controll.
  <input data-focus-id='input-1'/>
</ControlledFocus>

The value of activeElement must match the name in data-focus-id.

Development

For local development:

npm start

And open http://0.0.0.0:3000/demo.html.

Caveats

At this point there are a couple:

  • The biggest caveat of the current implementation is that there can be only one ControlledFocus component per page;
  • We still required a data attribute named data-focus-id on each component we wish to have focus controlled;
  • Depending on data-focus-id makes it hard to controll the focus on components that you don't own.