
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
unified-input
Advanced tools

Unified focus navigation and input using keyboard, gamepad, and mouse for ReactJS.
git clone git@github.com:whoisryosuke/react-unified-input.gitpnpmpnpm devOpen the app in your web browser, you should see the app.
npm i react-unified-input<InputManager /> to your app to enable focus navigation.useFocusable() hook inside a React component and pass the ref the underlying DOM element (see the ExampleFocusComponent for an example).Interested in learning more? Check out my blog, where I break down how this works.
You can control focus navigation a bit using the concept of "focus containers".
When you navigate, the algorithm will look for items in the same container first -- then look outside of it. This helps you create controlled focus areas, like a navigation or list.
We provide a FocusContainer out of the box, but you can also make your own if you need more custom behavior.
You can use the setFocusedItem() function exposed through the focus store, with the focusId exposed by the useFocusable() hook.
const ExampleFocusComponent = () => {
const { ref, focusId } = useFocusable<HTMLButtonElement>();
const { setFocusedItem } = useFocusStore();
// Focus item when it first loads
useEffect(() => {
setFocusedItem(focusId);
}, [])
//...your component here
}
If you need to change the keymap for keyboard or gamepad, you can use the setGamepadMap() function exposed through the focus store.
import { useFocusStore } from "react-unified-input"const { setGamepadMap } = useFocusStore();Sometimes in UI you need to convey the meaning behind a certain input. This is incredibly common in video game where the user needs to be reminded what button on their gamepad does what. We see this in games like Assassin's Creed or Kingdom Hearts. If you're playing on PlayStation with a gamepad you'll see their trademark symbols - but if you play on PC using a keyboard, you might see keyboard buttons instead.
These are commonly referred to as "key guides" and they are text and/or iconography that informs the user how their device interfaces with the application or game. And as I described, they're often adaptive to the current conditions - so if the user swaps devices, the key guides need to update to match the correct device.
We expose a currentDevice from the useFocusStore() hook that lets you know what was the last device in use.
Using this variable combined with keyboardMap and gamepadMap, you can create a <KeyGuide> component that displays the input to the user as their current device. So you can have a <KeyGuide input="confirm" /> that shows the user the "Enter" key on keyboard or the "X" key on gamepad.
You can also get the device name using deviceName to check if it's a DualSense, DualShock, Xbox, etc gamepad.
What happens when a component is animated but has focus? Ideally the focus travels with the element. And with this library - it does! - kinda.
When the user presses any button to navigate, the position of all focus items are updated. But if for some reason the focus isn't updating it's position at the rate you need, you can manually update the focus element's position using the updatePosition() function provided through the useFocusStore() hook.
You can see an example of this in ExampleAnimatedComponent.
package.jsonyarn buildnpm publishFAQs

We found that unified-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.