Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
@accessible/use-conditional-focus
Advanced tools
A React hook for focusing elements and their children conditionally.
npm i @accessible/use-conditional-focus
A React hook that will focus elements conditionally. By default this will focus on the first focusable child of the provided root element, but you can optionally include the root as well.
import * as React from 'react'
import useConditionalFocus from '@accessible/use-conditional-focus'
const Component = () => {
const ref = React.useRef(null)
const [visible, setVisible] = React.useState(false)
// Focuses the first focusable child in the `ref` element when
// visible is `true`
useConditionalFocus(ref, visible)
return (
<div>
<div ref={ref}>
// This button will be focused when `visible` is true
<button onClick={() => setVisible(false)}>Close me</button>
</div>
<button onClick={() => setVisible(true)}>Click me</button>
</div>
)
}
Prop | Type | Default | Required? | Description |
---|---|---|---|---|
target | React.RefObject<T> | T | Window | Document | null | Yes | A React ref, element, window , or document | |
shouldFocus | boolean | false | Yes | Provide a true value here to focus the first focusable child in the element. |
options | UseConditionalFocusOptions | {includeRoot: false, preventScroll: false} | No | See UseConditionalFocusOptions . |
UseConditonalFocusOptions
Prop | Type | Default | Required? | Description |
---|---|---|---|---|
includeRoot | boolean | false | No | When true this will try to focus on the root element in addition to its children. |
preventScroll | boolean | false | No | When true this will prevent your browser from scrolling the document to bring the newly-focused element into view. |
void
MIT
FAQs
A React hook for focusing elements and their children conditionally.
The npm package @accessible/use-conditional-focus receives a total of 1,734 weekly downloads. As such, @accessible/use-conditional-focus popularity was classified as popular.
We found that @accessible/use-conditional-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
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.