Socket
Socket
Sign inDemoInstall

@justinribeiro/toggle-tooltip

Package Overview
Dependencies
7
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @justinribeiro/toggle-tooltip

An accessible, fast, and WCAG 2.1 compliant toggle style tooltip web component using role=status.


Version published
Weekly downloads
4K
increased by23.45%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

toggle-tooltip

A small (8KB), accessible, fast, and WCAG 2.1 compliant toggle style tooltip web component using role=status.

Features

  1. WCAG 2.1 compliant:
  2. Fast: no jank repaint (turn on paint flashing in DevTools...nada)
  3. Screen reader friendly (interaction model allows explicit feedback)
  4. Supports optional hover (which is also compliant with WCAG 1.4.13)
  5. Basic styling with CSS custom properties

Demo / Screen Reader

To see the tooltip in action within JAWS 2020, see https://www.youtube.com/watch?v=PNH0RTB9alg

Install with Tools

Install the component:

npm i @justinribeiro/toggle-tooltip
# or
yarn add @justinribeiro/toggle-tooltip

Install with CDN

If you want the paste-and-go version, you can simply load it via CDN:

<script type="module" src="https://cdn.jsdelivr.net/npm/@justinribeiro/toggle-tooltip@1.0.3/dist/index.js">

Usage

Fire it up:

<script type="module">
   import '@justinribeiro/toggle-tooltip/index.js';
</script>
<toggle-tooltip><span slot="tooltip">
    I'm a tooltip!
  </span>
</toggle-tooltip>

See other uses in demo/index.html.

Development

$ git clone git@github.com:justinribeiro/toggle-tooltip.git
$ cd toggle-tooltip
$ yarn install
$ yarn start

# run the tests
$ yarn test

Properties

PropertyAttributeTypeDefaultDescription
hoverhoverbooleanfalseSetting hover as attribute on component allows for the mouseover and
mouseout events to become active for this instance of the toggle-tooltip

Note: this mode is complaint with WCAG SC 1.4.13 Content on Hover or Focus

TODO: I suppose I could watch for the change and then add/remove the event
handlers...but I don't have a use case for the at the moment
labellabelstring"'more info'"Define the internal button aria-label when an svg icon or other non-text
is used
showshowboolean"'more info'"Define the internal button aria-label when an svg icon or other non-text
is used

Methods

MethodTypeDescription
close(noReFocus?: boolean): voidClose the tooltip

oReFocus: Don't refocus to the button (probably because we
tabbed off and are moving through the document)
open(): voidOpen the tooltip and focus to it

Slots

NameDescription
Default slot injects into button value, useful for icon
tooltipAny message or links you'd like in the tooltip status message

CSS Custom Properties

PropertyDefault
--toggle-tooltip-button-background-color"transparent"
--toggle-tooltip-button-border"none"
--toggle-tooltip-button-padding0
--toggle-tooltip-status-background-color"#fafafa"
--toggle-tooltip-status-border"1px solid #ccc"
--toggle-tooltip-status-border-radius"0.5rem"
--toggle-tooltip-status-box-shadow"none"
--toggle-tooltip-status-padding"1rem"

Keywords

FAQs

Last updated on 12 Oct 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc