Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-aria/overlays

Package Overview
Dependencies
Maintainers
1
Versions
824
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/overlays

Spectrum UI components in React

  • 3.0.0-nightly.752
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3M
increased by3.86%
Maintainers
1
Weekly downloads
 
Created

What is @react-aria/overlays?

@react-aria/overlays is a library that provides accessible overlay components for React applications. It includes components for modals, popovers, and tooltips, ensuring they are accessible and follow best practices.

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

Modal

This code demonstrates how to create a modal using @react-aria/overlays. It includes state management for opening and closing the modal, and ensures accessibility features like preventing background scroll and proper focus management.

import { useOverlayTriggerState } from '@react-stately/overlays';
import { OverlayContainer, OverlayProvider, useModal, useOverlay, usePreventScroll } from '@react-aria/overlays';

function ModalExample() {
  let state = useOverlayTriggerState({});
  return (
    <OverlayProvider>
      <button onClick={() => state.open()}>Open Modal</button>
      {state.isOpen && (
        <OverlayContainer>
          <ModalDialog onClose={state.close} />
        </OverlayContainer>
      )}
    </OverlayProvider>
  );
}

function ModalDialog(props) {
  let ref = React.useRef();
  let { modalProps } = useModal();
  let { overlayProps } = useOverlay(props, ref);
  usePreventScroll();

  return (
    <div {...overlayProps} {...modalProps} ref={ref}>
      <h3>Modal Title</h3>
      <p>Modal Content</p>
      <button onClick={props.onClose}>Close</button>
    </div>
  );
}

Popover

This code demonstrates how to create a popover using @react-aria/overlays. It includes state management for opening and closing the popover, and ensures accessibility features like preventing background scroll and proper focus management.

import { useOverlayTriggerState } from '@react-stately/overlays';
import { OverlayContainer, OverlayProvider, useOverlay, usePreventScroll, usePopover } from '@react-aria/overlays';

function PopoverExample() {
  let state = useOverlayTriggerState({});
  return (
    <OverlayProvider>
      <button onClick={() => state.open()}>Open Popover</button>
      {state.isOpen && (
        <OverlayContainer>
          <PopoverDialog onClose={state.close} />
        </OverlayContainer>
      )}
    </OverlayProvider>
  );
}

function PopoverDialog(props) {
  let ref = React.useRef();
  let { popoverProps } = usePopover(props, ref);
  let { overlayProps } = useOverlay(props, ref);
  usePreventScroll();

  return (
    <div {...overlayProps} {...popoverProps} ref={ref}>
      <h3>Popover Title</h3>
      <p>Popover Content</p>
      <button onClick={props.onClose}>Close</button>
    </div>
  );
}

Tooltip

This code demonstrates how to create a tooltip using @react-aria/overlays. It includes state management for showing and hiding the tooltip, and ensures accessibility features like proper focus management and delay handling.

import { useTooltipTriggerState } from '@react-stately/tooltip';
import { useTooltip, TooltipTrigger, Tooltip } from '@react-aria/tooltip';

function TooltipExample() {
  let state = useTooltipTriggerState({});
  return (
    <TooltipTrigger state={state} delay={300} placement="top">
      <button>Hover or focus me</button>
      <Tooltip>Tooltip Content</Tooltip>
    </TooltipTrigger>
  );
}

Other packages similar to @react-aria/overlays

FAQs

Package last updated on 24 Oct 2020

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc