Socket
Socket
Sign inDemoInstall

@spectrum-web-components/tooltip

Package Overview
Dependencies
24
Maintainers
7
Versions
236
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @spectrum-web-components/tooltip

`sp-tooltip` allow users to get contextual help or information about specific components when hovering or focusing on them.


Version published
Weekly downloads
2.3K
increased by14.73%
Maintainers
7
Created
Weekly downloads
 

Changelog

Source

0.40.5 (2024-02-05)

Bug Fixes

  • button: use larger icons in Close Button (c4aa02c)
  • combobox: add combobox pattern (#3894) (47d7d71), closes #3887
  • menu: process ":active" styles (7917583)
  • slider: reimplement gradient slider track application (a10b91e)
  • tabs: account for the indicator bar in the overflow decorator (f4a8744)
  • theme: expose version property (#3978) (d42bb71)
  • theme: include custom Spectrum color tokens in Express color tokens (370a1f1)

Readme

Source

Description

sp-tooltip allow users to get contextual help or information about specific components when hovering or focusing on them.

Usage

See it on NPM! How big is this package in your project? Try it on webcomponents.dev

yarn add @spectrum-web-components/tooltip

Import the side effectful registration of <sp-tooltip> via:

import '@spectrum-web-components/tooltip/sp-tooltip.js';

When looking to leverage the Tooltip base class as a type and/or for extension purposes, do so via:

import { Tooltip } from '@spectrum-web-components/tooltip';

Example

Tooltips can be top, bottom, left, or right.

<sp-tooltip open placement="top">Label</sp-tooltip>
<br />
<br />
<sp-tooltip open placement="bottom">Label</sp-tooltip>
<br />
<br />
<sp-tooltip open placement="left">Label</sp-tooltip>
<br />
<br />
<sp-tooltip open placement="right">Label</sp-tooltip>

Self-managed overlays

By default, Tooltip provides styling without behavior. You must combine it with an Overlay Trigger in order to manage its overlay behavior.

You can use the tooltip as the descendant of an interactive element, such as Action Button, by applying the self-managed attribute which automatically binds the Tooltip to its first interactive ancestor element's focus/hover interactions:

<sp-action-button>
    Trigger
    <sp-tooltip self-managed>Content</sp-tooltip>
</sp-action-button>

This is especially useful when inserting an intermediate <overlay-trigger> would interfere with parent/child relationships, such as between <sp-action-group> and <sp-action-button>.

Note that an interactive element is an element that can receive focus during tab navigation, such as sp-action-button, sp-action-menu, sp-field-label etc.

Given that tooltip is not focusable by itself, it would not show up during tab navigation. Thus a tooltip would not be accessible if used with a non-interactive element, such as <sp-icon-*>.

The correct way to make it accessible would be to wrap it under an interactive element, such as sp-action-button:

<sp-action-button size="s">
    <sp-icon-info></sp-icon-info>
    <sp-tooltip self-managed placement="right">
        Display something here
    </sp-tooltip>
</sp-action-button>

Variants

Informative

This is the informative or info variant of Tooltip

<sp-tooltip open placement="top" variant="info">Label</sp-tooltip>
<sp-tooltip open placement="top" variant="info">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit
</sp-tooltip>
<sp-tooltip open placement="top" variant="info">
    <sp-icon-info slot="icon" size="s"></sp-icon-info>
    Label
</sp-tooltip>
<sp-tooltip open placement="top" variant="info">
    <sp-icon-info slot="icon" size="s"></sp-icon-info>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit
</sp-tooltip>

Positive

This is the postive (a.k.a.) success variant of Tooltip

<sp-tooltip open placement="top" variant="positive">Label</sp-tooltip>
<sp-tooltip open placement="top" variant="positive">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit
</sp-tooltip>
<sp-tooltip open placement="top" variant="positive">
    <sp-icon-checkmark-circle slot="icon" size="s"></sp-icon-checkmark-circle>
    Label
</sp-tooltip>
<sp-tooltip open placement="top" variant="positive">
    <sp-icon-checkmark-circle slot="icon" size="s"></sp-icon-checkmark-circle>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit
</sp-tooltip>

Negative

This is the negative a.k.a. error variant of Tooltip

<sp-tooltip open placement="top" variant="negative">Label</sp-tooltip>
<sp-tooltip open placement="top" variant="negative">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit
</sp-tooltip>
<sp-tooltip open placement="top" variant="negative">
    <sp-icon-alert slot="icon" size="s"></sp-icon-alert>
    Label
</sp-tooltip>
<sp-tooltip open placement="top" variant="negative">
    <sp-icon-alert slot="icon" size="s"></sp-icon-alert>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit
</sp-tooltip>

Keywords

FAQs

Last updated on 05 Feb 2024

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