npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

the-only-react-tooltip

v2.0.2

Published

Modern, simple, and accessible tooltip for React.

Downloads

13

Readme



Why does every React tooltip package have to be so bloated and complex? Use the-only-react-tooltip when you:

Includes definitions for TypeScript.

Notes on accessibility

Tooltips shouldn't break accessibility, but they often do. This package does it's best to be as accessible as possible:

  • Tooltip appears on hover, on focus events (such as tab), and on touch events.
  • Tooltip can be dismissed by pressing escape, or by touching anywhere on the page.
  • Uses the HTML native title attribute when the tooltip can't be displayed (see props below).
  • Uses all relevant ARIA attributes (see props below).

The developer should still be responsible! Try not to display anything more than basic text, and don't display tooltips on UI elements that can be interacted with in some other way, like a non-disabled button (mobile users won't have time to read the tooltip before the button action is executed).

See how this component adheres to the ARIA design pattern for tooltips.

Installation

NPM

Via NPM or Yarn:

npm install the-only-react-tooltip
yarn add the-only-react-tooltip

Usage

Using NPM

1 . Import the-only-react-tooltip after installation

import Tooltip from 'the-only-react-tooltip'

2 . Wrap your DOM node or React component with Tooltip (They will be used as the hover target):

<Tooltip body={"I'll be shown on hover of YourReactComponent"}>
  <YourReactComponent ... />
</Tooltip>

2 . The component may be extended by importing its props and state:

import Tooltip, { TooltipProps, TooltipState } from 'the-only-react-tooltip'

Props

Name | Type | Required? | Default | Notes |:--- |:--- |:--- |:--- |:-- children | JSX.Element or string | Yes | - | The hover target to display the tooltip is added to children, and the DOMRect of children is used to correctly position the tooltip. body | ReactNode | Yes | - | Contents of the tooltip. It's suggested to use a plain string, but arbitrary ReactNode's are allowed to permit for styled strings and component library string components. position | "top" | "bottom" | "left" | "right" | No | - | Override the default positioning algorithm and always show the tooltip on one side. title | string | No | - | For accessibility - if the tooltip can't be shown, this will be added to children as the title attribute and shown instead. ariaEssential | boolean | No | false | Sets the ARIA importance of the tooltip. true -> aria-labelledBy (implies essential information), false -> aria-describedBy (implies additional information). If you're setting this to true, rethink your use of a tooltip! tooltipId | string | No | tooltip | Sets the ID of the tooltip that will be used as the id of the base HTML element, as well as the value of aria-describedBy and aria-labelledBy. Make sure you set this to a unique value if you're using more that one tooltip on your page.

Example / Local development

This package ships with a basic example served with webpack-dev-server. This can be used to test changes during development:

npm run dev

License

MIT - see license.md for full details.

Maintainers

kgrillis