Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
ink-focus
Advanced tools
Readme
An Ink component to manage element focus and ease your mind.
$ npm install ink-focus
This module exports two components.
const React = require("react")
const Ink = require("ink")
const { FocusManager } = require("ink-focus")
Ink.render(
<FocusManager tab onFocusChange={(_, i) => console.log(`Text ${i + 1} focused`)}>
<Ink.Text>Text 1</Ink.Text>
<Ink.Text>Text 2</Ink.Text>
<Ink.Text>Text 3</Ink.Text>
</FocusManager>
)
For more advanced usage, see Focusable.
The main component, which will contain all of your focusable elements and handle keypress events.
Note that, currently, FocusManagers can't be nested; attempting to do so will throw an error.
Note that none of the key props default to true
, so you'll have to specify at least one of them to make the FocusManager interactive.
Whether Tab presses should change the focus to the next element.
boolean
false
Whether ← and → (horizontal arrow key) presses should change the focus to the previous and next element, respectively.
boolean
false
Whether ↑ and ↓ (vertical arrow key) presses should change the focus to the previous and next element, respectively.
boolean
false
xArrows
and yArrows
. Whether all arrows should change the focus.
boolean
false
Custom filter to check whether a keypress should change focus or not. Return "prev"
to change focus to the previous element, "next"
to change focus to the next one, and any other value to not do anything. Check out the keypress module to see what arguments are passed to the callback.
function(char: string, key?: object) => "prev" | "next" | any
undefined
Whether the focus should loop back to the start when there are no elements next, and loop to the end when there are no elements prior.
boolean
false
Whether no element should be focused by default; the first (or last) element will only be focused once the user presses a key.
boolean
false
Callback run once the focus changes.
function(oldIndex?: number, newIndex: number) => void
undefined
The children of a FocusManager ("focusable elements") can have these props.
Whether the element is focused. This prop is set by FocusManager, though you can set it yourself to set a default focused element other than the first one.
boolean
Whether the element should not be focusable; it should be "skipped" if the user attempts to focus it.
boolean
Callback run once the element is focused.
function() => void
Callback run once the element is "blurred" (stops being focused).
function() => void
A utility component, which isn't strictly necessary—you can place elements other than Focusables inside FocusManagers—but can be useful if the content of the FocusManager isn't solely custom components. It handles prop swapping depending on whether the element is focused.
All FocusManager children props, and all Ink.Box props, which will be passed to the container Box.
Props to pass to the container Ink.Box when the element is focused.
object
Check out examples/main.js for an example of (two) custom-made focusable components, they handle styling so you don't have to inline the focus prop every time. They're similar to the Focusable implementation.
Psst! for focusable buttons, check out ink-button.
You'll notice that pressing Ctrl+C (or any other combination) won't exit the program. This happens because ink-focus
keeps listening for user keypresses. To fix this, add something like this to your code (preferably your main file; index.js
, cli.js
...):
process.stdin.on("keypress", (char, key) => {
if (key && key.ctrl && key.name === "c") {
process.exit(0)
}
})
This will listen for keypress events, and exit the program once the Ctrl+C combination is detected.
FAQs
An [Ink](https://github.com/vadimdemedes/ink) component to manage element focus and _ease your mind_.
The npm package ink-focus receives a total of 0 weekly downloads. As such, ink-focus popularity was classified as not popular.
We found that ink-focus 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.