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

ember-tooltips

Package Overview
Dependencies
Maintainers
2
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-tooltips

Easy and extendible tooltips for Ember

  • 3.0.0-beta.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22K
decreased by-1.47%
Maintainers
2
Weekly downloads
 
Created
Source

Ember-tooltips (and popovers) Build Status npm Ember Observer Score

Render tooltips and popovers on components and other HTML elements using HTMLBars.

Installation

ember install ember-tooltips

Documentation

Documentation for usage is below:

Usage

Ember Tooltip

The easiest way to add a tooltip to any element is with the {{ember-tooltip}} component:

{{#my-component}}
  Hover for more info

  {{ember-tooltip text='Here is more info!'}}
{{/my-component}}

Or in block form:

{{#my-component}}
  Hover for more info

  {{#tooltip}}
    Here is the info in a tooltip!
  {{/ember-tooltip}}
{{/my-component}}

The tooltip will always be rendered on its parent element unless you specify the targetId attribute:

{{input id='has-info-tooltip'}}

{{#ember-tooltip targetId='has-info-tooltip'}}
  Here is some more info
{{/ember-tooltip}}

Tooltips and popovers are lazy rendered. That means the are only rendered in the DOM once the user interacts with the target element.

Options can be set on the {{ember-tooltip}} as attributes:

{{#my-component}}
  Click for more info

  {{#ember-tooltip event='click'}}
    This info will show on click!
  {{/ember-tooltip}}
{{/my-component}}

Documentation for supported options is located here.

Ember popover

Popovers can be created with the {{ember-popover}} component, which is added to apps just like {{ember-tooltip}}.

Popovers support the same target behavior as tooltips; popovers will render on their parent element unless a targetId is supplied.

All the options passed to tooltip components can be passed to popover components:

{{#my-component}}
  Click for more info

  {{#ember-popover event='click'}}
    This info will show in a popover on click!
  {{/ember-popover}}
{{/my-component}}

Popovers also benefit from a hide API made publically acessible:

{{#ember-popover as |popover|}}
  Click <a href {{action 'hide' target=popover}}>here</a> to hide the popover
{{/ember-popover}}

In addition, a popoverHideDelay option is made available for popovers only.

Targets

The concept of a 'target' is used through this addon. A target is the element that the tooltip or popover is attached to. Each tooltip or popvers has its own target. Interacting with this target will render and/or show the tooltip or popover.

For example, if you want to show a tooltip over a button when the user hovers over the button, the button is the target. If you want to show a popover over an input when the user focuses on the input, the input is the target.

Options

Options are set as attributes on the tooltip/popover components. Current tooltip/popover properties this addon supports are:

Class
TypeString
Defaultnone

Adds a class to any tooltip:

{{ember-tooltip class='tooltip-warning'}}
Delay
TypeNumber
Default0

Delays showing the tooltip by the given number of milliseconds.

{{!--Delays the show animation by 500ms--}}

{{ember-tooltip delay=500}}

This does not affect the hiding of the tooltip. See also, delayOnChange.

Delay on change
TypeBoolean
Defaulttrue

Whether or not to enforce the delay even when the user transitions their cursor between multiple target elements with tooltips.

See this animation for a visual explanation:

{{!--Forces delay to be enforced when the user skips
between elements with tooltips--}}

{{ember-tooltip delayOnChange=true}}
Duration
TypeNumber
Default0

Sets the duration for which the tooltip will be open, in milliseconds. When the tooltip has been opened for the duration set it will hide itself.

The user will still hide the tooltip if the hide event occurs before the duration expires.

{{!-- Closes the tooltip after 1000ms--}}

{{ember-tooltip duration=1000}}

Leave as 0 if you wish for the tooltip to remain open indefinitely.

Effect
TypeString
Default'slide'

Sets the animation used to show and hide the tooltip. Possible options are:

  • 'fade'
  • 'slide'
  • 'none'
{{ember-tooltip effect='slide'}}
Event
TypeString
Default'hover'

The event that the tooltip will hide and show for. Possible options are:

  • 'hover'
  • 'click'
  • 'focus' (hides on blur)
  • 'none'
{{ember-tooltip event='click'}}

This event is overwritten by the individual hideOn and showOn properties. In effect, setting event sets hideOn and shownOn for you.

The tooltip can also be shown programatically by passing in the isShown property, documented here.

Hide on
TypeString
Default'none'

Sets the event that the tooltip will hide on. This overwrites any event set with the event option.

This can be any javascript-emitted event.

{{!--This tooltip will hide on mouseleave, NOT click--}}

{{ember-tooltip
  event='click'
  hideOn='mouseleave'
}}

Usually, you'll use the event option, which sets showOn and hideOn automatically, instead of this option.

This opeion does not affect the event the tooltip shows on. That is set by the showOn option. This will override the event property in deciding when the tooltip is hidden.

Side
TypeString
Default'top'

Sets the side the tooltip will render on. If keepInWindow is set to true, side can be overwritten to keep the tooltip on screen.

Possible options are:

  • 'top'
  • 'right'
  • 'bottom'
  • 'left'
{{!--The tooltip will render on the right of the target element--}}

{{ember-tooltip
  side='right'
}}
Show on
TypeString
Default'none'

Sets the event that the tooltip will show on. This overwrites any event set with the event option.

This can be any javascript-emitted event.

{{!--This tooltip will show on click, NOT hover--}}

{{ember-tooltip
  showOn='click'
}}

Usually, you'll use the event option, which sets showOn and hideOn automatically, instead of this option.

This opeion does not affect the event the tooltip hides on. That is set by the hideOn option. This will override the event property in deciding when the tooltip is shown.

Spacing
TypeNumber
Default10

Sets the number of pixels the tooltip will render from the target element. A higher number will move the tooltip further from the target. This can be any number.

{{!--Render the tooltip 20px from the target element--}}
{{ember-tooltip spacing=20}}
Text
TypeString
Defaultnull

Sets the text of any tooltip without needing the tooltip to be written in block form.

{{#my-component}}
  Hover for more info

  {{ember-tooltip text='Here is more info!'}}
{{/my-component}}
Is Shown
TypeBoolean
Defaultfalse

Gives you a programatic way to hide and show a tooltip. Set this value to true to manually show the tooltip.

This can be useful alongside event='none' when you only want to toolip to show when you specific and not based on an user action.

{{!--Binds the tooltip visibility to the showTooltip property--}}
{{ember-tooltip isShown=true event='none'}}
Hide delay
TypeNumber
Default250

POPOVER ONLY: The number of milliseconds before the popover will hide after the user hovers away from the popover and the popover target. This is only applicable when event='hover'.

{{ember-popover event='hover' hideDelay=300}}

popover-hover

Setting Defaults

You can set the default for any option by extending the {{ember-tooltip}} or {{ember-popover}} component:

{{!--your-app/components/ember-tooltip}}--}}

import EmberTooltipComponent from 'ember-tooltips/components/ember-tooltip';

export default EmberTooltipComponent.extend({
  effect: 'fade',
  side: 'bottom',
});

Actions

Four actions are available for you to hook onto through the tooltip/popover lifecycle:

{{ember-tooltip
  onDestroy=(action 'onDestroy')
  onHide=(action 'onHide')
  onRender=(action 'onRender')
  onShow=(action 'onShow')
}}

As of 2.11.0, specifying just the name of an action (e.g. 'onDestroy') is deprecated, and will be removed in 3.0.0. Please use closure actions instead.

Testing

Test helpers

This addon exposes testing helpers which can be used inside of the consuming app's acceptance and integration tests. We use a tooltip-centric naming convention but these can also be used to test popovers.

Publically available test helpers are:

All assert helpers require assert to be passed as the first param and some accept a second, optional param for additional test options. For detailed usage instructions and examples, see the documentation for each test helper below.

All test helpers can be imported from the following path:

'ember-tooltips/test-support';

For example:

// appname/tests/integration/components/some-component.js

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, triggerEvent } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

import { assertTooltipRendered } from 'ember-tooltips/test-support';

module('Integration | Component | Some component', function(hooks) {
  setupRenderingTest(hooks);

  test('ember-tooltip renders', async function(assert) {

    await render(hbs`{{ember-tooltip isShown=true}}`);

    assertTooltipRendered(assert);
  });
});
assertTooltipContent()

Asserts that a tooltip or popover has content that matches a given string.

import { assertTooltipContent } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip text='More info' isShown='true'}}`);

  assertTooltipContent(assert, {
    contentString: 'More info',
  });
});
assertTooltipRendered()

Asserts that a tooltip or popover has been rendered in the DOM.

import { render, triggerEvent } from '@ember/test-helpers';
import { assertTooltipRendered } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip}}`);

  await triggerEvent(this.element, 'mouseenter');

  assertTooltipRendered(assert);
});

Please note, assertTooltipRendered() does not assert that the tooltip or popover is visible to the user - use assertTooltipVisible() for that.

Given this addon's lazy rendering capabilities (explained in Targets), tooltips will not be rendered until the target is interacted with.

The options hash accepts:

assertTooltipNotRendered()

Asserts that a tooltip or popover has not been rendered in the DOM.

Why is this test helper useful? Well, given this addon's lazy rendering capabilities (explained in Targets), tooltips may not be rendered until the target is interacted with.

import { render, triggerEvent } from '@ember/test-helpers';
import { assertTooltipNotRendered } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip}}`);

  assertTooltipNotRendered(assert);
});

This helper does not assert that the tooltip or popover is not visible to the user. The assertion will fail if the tooltip or popover is not visible to the user but is still rendered in the DOM. If you want to assert that a tooltip or popover is not visible once it's rendered in the DOM, use assertTooltipNotVisible().

The options hash accepts:

assertTooltipVisible()

Asserts that a tooltip or popover is visible.

For example:

import { render, triggerEvent } from '@ember/test-helpers';
import { assertTooltipVisible } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip}}`);

  await triggerEvent(this, this.element);

  assertTooltipVisible(assert);
});

You may use this helper with a variety of different user interactions. Here's an example that asserts that a tooltip is shown when the user focusses on an input:

import { render, triggerEvent } from '@ember/test-helpers';
import { assertTooltipVisible } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`
    <input id="url-input">
    {{ember-tooltip targetId='url-input'}}
  `);

  await triggerEvent($('#url-input')[0], 'focus');

  /* Asserts that the tooltip is made visible when the user focuses on the input */

  assertTooltipVisible(assert);
});

The options hash accepts:

assertTooltipNotVisible()

Asserts that a tooltip or popover is not visible.

This helper is usually used in conjunction with triggerTooltipTargetEvent() to assert that a particular user interaction hides a tooltip to the user.

For example:

import { render, triggerEvent } from '@ember/test-helpers';
import {
  assertTooltipNotVisible,
  assertTooltipVisible,
} from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip}}`);

  const { element } = this;

  /* Hover over the target to show the tooltip... */

  await triggerEvent(element, 'mouseenter');

  assertTooltipVisible(assert);

  /* Stop hovering over the target in order to hide the tooltip... */

  await triggerEvent(element, 'mouseleave');

  assertTooltipNotVisible(assert);
});

The options hash accepts:

assertTooltipSide()

Asserts that a tooltip or popover is rendered on the correct side of the target.

This helper tests the side option that can be passed to tooltips and popovers.

An options hash is required and it must contain a side property. For example:

import { assertTooltipSide } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip side='right' isShown=true}}`);

  /* Asserts that the tooltip is rendered but not shown when the user hovers over the target, which is this test's element */

  assertTooltipSide(assert, {
    side: 'right',
  });
});

The options hash accepts:

assertTooltipSpacing()

Asserts that a tooltip or popover is rendered a given number of pixels from the target.

This helper tests the spacing option that can be passed to tooltips and popovers.

An options hash is required and it must contain spacing and side properties. For example:

import { assertTooltipSide } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip spacing=35 isShown=true}}`);

  /* Asserts that the tooltip is rendered but not shown when the user hovers over the target, which is this test's element */

  assertTooltipSide(assert, {
    side: 'right', // Side is required
    spacing: 35,
  });
});

The options hash accepts:

Test helper options

Most test helpers accept a second, optional param called options. This is an object you can pass that customizes various options in a test. The properties you can pass via options for each test helper is listed above. Below you will find more information for each property.

Test helper option: contentString

The content string you expect the tooltip or popover to have.

TypeString
Defaultnull

Usage example:

import { assertTooltipContent } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip text='More info' isShown='true'}}`);

  assertTooltipContent(assert, {
    contentString: 'More info',
  });
});
Test helper option: selector

The selector of the tooltip or popover you are testing.

If more than one tooltip or popover is found in the DOM when you run an assertion, you will be asked to specify this.

TypeString
Default'.ember-tooltip, .ember-popover'

Usage example:

import { render, triggerEvent } from '@ember/test-helpers';
import { assertTooltipVisible } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`
    {{ember-tooltip}}
    {{ember-tooltip class="differentiator"}}
  `);

  await triggerEvent(this, this.element);

  assertTooltipVisible(assert, {
    selector: '.differentiator', // Or whatever class you added to the desired tooltip
  });
});
Test helper option: side

The value for the tooltip or popover's side option that you are asserting.

TypeString
Defaultnull

For example, if you specify for the tooltip or popover be shown on the right of the target using side='right', you will pass side: 'right' in assertions that test side. Here is the code for this example:

import { assertTooltipSide } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip side='right' isShown=true}}`);

  /* Asserts that the tooltip is rendered but not shown when the user hovers over the target, which is this test's element */

  assertTooltipSide(assert, {
    side: 'right',
  });
});
Test helper option: spacing

The value for the tooltip or popover's spacing option that you are asserting. Specify as a number of pixels expected (without a px unit).

TypeNumber
Defaultnull

For example, if you specify for the tooltip or popover be shown on the right of the target using side='right', you will pass side: 'right' in assertions that test side. Here is the code for this example:

import { assertTooltipSide } from 'ember-tooltips/test-support';

test('Example test', async function(assert) {

  await render(hbs`{{ember-tooltip spacing=35 isShown=true}}`);

  /* Asserts that the tooltip is rendered but not shown when the user hovers over the target, which is this test's element */

  assertTooltipSide(assert, {
    side: 'right', // Side is required
    spacing: 35,
  });
});

Accessibility

This addon aims to meet 508 compliance.

Elements with tooltips are given a tabindex attribute and when the element receives focus, the tooltip with show.

Additionally, the aria-describedby, title, id, and role attributes are managed by this addon.

There is always room for improvement and PRs to improve accessibility are welcome.

Development

This project is maintained by:

Duncan WalkerMax Fierke
Duncan WalkerMax Fierke

All PRs and issues are welcome.

You can setup a dev environment for this addon as follows:

git clone https://github.com/sir-dunxalot/ember-tooltips.git
cd ember-tooltips
npm install
ember s # Starts server

Please include tests and documentation updates with any new features.

To run the test suite, visit the /tests route in the browser.

You can also run the test suite in the CLI:

ember test # Runs the test suite once
ember try:testall # Runs tests in all scenarios in config/ember-try.js
ember try:one ember-lts-2.18 --- ember serve # Runs the test suite in the given ember-try scenario

To release an update to the demo app (for maintainers only):

```sh
git checkout master # make sure you're on master branch
ember github-pages:commit --message "Some commit message" # Builds the app
git push origin gh-pages:gh-pages # Deploys the app

Keywords

FAQs

Package last updated on 21 Sep 2018

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