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

@react-aria/tooltip

Package Overview
Dependencies
Maintainers
2
Versions
774
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/tooltip

Spectrum UI components in React

  • 3.0.0-nightly-a45e2a5ec-241011
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
861K
increased by9.99%
Maintainers
2
Weekly downloads
 
Created

What is @react-aria/tooltip?

@react-aria/tooltip is a React library that provides accessible tooltip components. It is part of the React Aria collection of hooks and components designed to help developers build accessible web applications. The package ensures that tooltips are compliant with ARIA (Accessible Rich Internet Applications) standards, making them usable for people with disabilities.

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

Basic Tooltip

This code demonstrates a basic tooltip implementation using @react-aria/tooltip. It includes a button that, when hovered over or focused, displays a tooltip with the text 'Tooltip content'. The tooltip is accessible and follows ARIA standards.

```jsx
import { useTooltip, useTooltipTrigger } from '@react-aria/tooltip';
import { useTooltipTriggerState } from '@react-stately/tooltip';

function TooltipExample() {
  let state = useTooltipTriggerState();
  let ref = React.useRef();
  let { triggerProps, tooltipProps } = useTooltipTrigger({ state }, ref);
  let { tooltipProps: ariaTooltipProps } = useTooltip({ state });

  return (
    <div>
      <button {...triggerProps} ref={ref}>Hover or focus me</button>
      {state.isOpen && (
        <div {...ariaTooltipProps} {...tooltipProps}>
          Tooltip content
        </div>
      )}
    </div>
  );
}
```

Custom Styling

This example shows how to apply custom styling to the tooltip. The tooltip content is styled with a black background, white text, padding, and rounded corners.

```jsx
import { useTooltip, useTooltipTrigger } from '@react-aria/tooltip';
import { useTooltipTriggerState } from '@react-stately/tooltip';

function CustomTooltipExample() {
  let state = useTooltipTriggerState();
  let ref = React.useRef();
  let { triggerProps, tooltipProps } = useTooltipTrigger({ state }, ref);
  let { tooltipProps: ariaTooltipProps } = useTooltip({ state });

  return (
    <div>
      <button {...triggerProps} ref={ref}>Hover or focus me</button>
      {state.isOpen && (
        <div {...ariaTooltipProps} {...tooltipProps} style={{ backgroundColor: 'black', color: 'white', padding: '5px', borderRadius: '3px' }}>
          Custom styled tooltip content
        </div>
      )}
    </div>
  );
}
```

Tooltip with Delay

This example demonstrates how to add a delay to the tooltip display. The tooltip will appear 500 milliseconds after the button is hovered over or focused.

```jsx
import { useTooltip, useTooltipTrigger } from '@react-aria/tooltip';
import { useTooltipTriggerState } from '@react-stately/tooltip';

function DelayedTooltipExample() {
  let state = useTooltipTriggerState({ delay: 500 });
  let ref = React.useRef();
  let { triggerProps, tooltipProps } = useTooltipTrigger({ state }, ref);
  let { tooltipProps: ariaTooltipProps } = useTooltip({ state });

  return (
    <div>
      <button {...triggerProps} ref={ref}>Hover or focus me</button>
      {state.isOpen && (
        <div {...ariaTooltipProps} {...tooltipProps}>
          Tooltip with delay
        </div>
      )}
    </div>
  );
}
```

Other packages similar to @react-aria/tooltip

FAQs

Package last updated on 11 Oct 2024

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