Socket
Socket
Sign inDemoInstall

@react-aria/dialog

Package Overview
Dependencies
Maintainers
2
Versions
713
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/dialog

Spectrum UI components in React


Version published
Maintainers
2
Created

Package description

What is @react-aria/dialog?

@react-aria/dialog is a package that provides accessible dialog components for React applications. It is part of the React Aria library, which offers a collection of hooks that implement accessible UI patterns. The package helps developers create modal dialogs that are fully accessible, including proper focus management and ARIA attributes.

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

Basic Dialog

This code sample demonstrates how to create a basic accessible dialog using the @react-aria/dialog package. It includes a button to open the dialog, and the dialog itself contains a title, some content, and a button to close the dialog.

```jsx
import { useDialog } from '@react-aria/dialog';
import { useOverlayTriggerState } from '@react-stately/overlays';
import { OverlayContainer, Overlay } from '@react-aria/overlays';

function DialogExample() {
  let state = useOverlayTriggerState({});
  let ref = React.useRef();
  let { dialogProps } = useDialog({}, ref);

  return (
    <>
      <button onClick={() => state.open()}>Open Dialog</button>
      {state.isOpen && (
        <OverlayContainer>
          <Overlay>
            <div {...dialogProps} ref={ref}>
              <h3>Dialog Title</h3>
              <p>Dialog content goes here.</p>
              <button onClick={() => state.close()}>Close</button>
            </div>
          </Overlay>
        </OverlayContainer>
      )}
    </>
  );
}
```

Focus Management

This code sample demonstrates how to manage focus within the dialog using the FocusScope component from @react-aria/focus. It ensures that focus is contained within the dialog while it is open and restores focus to the trigger element when the dialog is closed.

```jsx
import { useDialog } from '@react-aria/dialog';
import { useOverlayTriggerState } from '@react-stately/overlays';
import { OverlayContainer, Overlay } from '@react-aria/overlays';
import { FocusScope } from '@react-aria/focus';

function FocusManagedDialog() {
  let state = useOverlayTriggerState({});
  let ref = React.useRef();
  let { dialogProps } = useDialog({}, ref);

  return (
    <>
      <button onClick={() => state.open()}>Open Dialog</button>
      {state.isOpen && (
        <OverlayContainer>
          <Overlay>
            <FocusScope contain restoreFocus autoFocus>
              <div {...dialogProps} ref={ref}>
                <h3>Dialog Title</h3>
                <p>Dialog content goes here.</p>
                <button onClick={() => state.close()}>Close</button>
              </div>
            </FocusScope>
          </Overlay>
        </OverlayContainer>
      )}
    </>
  );
}
```

Other packages similar to @react-aria/dialog

Readme

Source

@react-aria/dialog

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