Socket
Socket
Sign inDemoInstall

@react-aria/focus

Package Overview
Dependencies
Maintainers
2
Versions
730
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/focus

Spectrum UI components in React


Version published
Weekly downloads
1.9M
increased by1.52%
Maintainers
2
Weekly downloads
 
Created

Package description

What is @react-aria/focus?

@react-aria/focus is a library that provides accessible focus management utilities for React applications. It helps in managing focus behavior in a way that is compliant with accessibility standards.

What are @react-aria/focus's main functionalities?

useFocusRing

The `useFocusRing` hook provides a way to apply focus styles to an element when it is focused. It returns properties to spread on the element and a boolean indicating if the focus is visible.

import { useFocusRing } from '@react-aria/focus';

function MyComponent() {
  let { isFocusVisible, focusProps } = useFocusRing();
  return (
    <button {...focusProps} style={{ outline: isFocusVisible ? '2px solid blue' : 'none' }}>
      Click me
    </button>
  );
}

FocusScope

The `FocusScope` component manages focus within a contained area. It ensures that focus stays within the scope and can restore focus to the previously focused element when the scope is unmounted.

import { FocusScope } from '@react-aria/focus';

function MyComponent() {
  return (
    <FocusScope contain restoreFocus autoFocus>
      <input placeholder="First input" />
      <input placeholder="Second input" />
    </FocusScope>
  );
}

useFocusWithin

The `useFocusWithin` hook provides a way to detect if any element within a container has focus. It returns properties to spread on the container and a boolean indicating if focus is within the container.

import { useFocusWithin } from '@react-aria/focus';

function MyComponent() {
  let { isFocusWithin, focusWithinProps } = useFocusWithin();
  return (
    <div {...focusWithinProps} style={{ border: isFocusWithin ? '2px solid green' : 'none' }}>
      <input placeholder="Focus within me" />
    </div>
  );
}

Other packages similar to @react-aria/focus

Readme

Source

@react-aria/focus

This package is part of react-spectrum. See the repo for more details.

FAQs

Package last updated on 09 Nov 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc