Dependencies

NameFile
Core/dist/js/core.js

Assets

TypeFile
jsdist/js/tooltip.js
cssdist/css/tooltip.css
lessdist/less/tooltip.less
scssdist/scss/tooltip.scss

Examples

There are 12 different positions you can set on your tooltip modals. If there is not room for you modal to fit in the viewport size, it will make up to five attempts at being smart and positioning the modal in view.

Tooltip

Some contents.

Or you can provide a position of "none" to ignore all positioning logic.

Tooltip As Attribute

Supply tooltip triggers with an aria-label attribute which will be consumed by Tooltip and generate a modal. HTML in the attribute is also acceptable.

Tooltip As Sibling

You can also provide your own tooltip modal by creating a sibling element of your .mk-tt (trigger) with a class name of .mk-tt-moal.

Tooltip Title

Tooltip Content.

Tooltip Anywhere in the Document

You can put a tooltip modal in any place possible, really. If you decide your tooltip modal needs placement somewhere other than as a sibling or child element of the trigger, link them by id and aria-describedby attribute.

Tooltip by Click

Tooltips don't have to be triggered by mouseenter. Set the data-action attribute to "click" on the tooltip trigger and mouse events will be ignored, while click events will be enabled.

Tooltip Title

Tooltip Content.

Interactive Tooltips

If your tooltip contains focusable content (ie: links, form elements, etc) it will become a dialog. Basically what this means is it's read differently by screen readers and behaviors change. You can tab and interact with the elements inside the tooltip. Focus then becomes more like a Modal. With dialog types, add any element inside the modal with a data-action attribute of "close" to trigger closing the modal.

*Interactive tooltips are only available with click/keyboard events (data-action of "click" or relying on keyboard tabbing) NOT mouseover events. This is intentional as it is considered bad design to have interactivity within the content of mouseover/out elements.

Links & Forms

Oh look at all these neat little elements we've piled into our tooltip.

Scroll-Y Container

We support nested scrolling containers (Y). This example has the tooltip triggers inside a container of overflow-y, while the modal sits outside the container (not necessary, you may put the tooltips inside the container as well). We've also only created one modal, which all ten tooltips share.

Tooltip Title

Tooltip Content.

Scroll-X Container

We support nested scrolling containers (x). This example has the tooltip triggers inside a container of overflow-x, while the modal sits outside the container (not necessary, you may put the tooltips inside the container as well). We've also only created one modal, which all ten tooltips share.

Tooltip Title

Tooltip Content.

Tooltip Title

Tooltip Content.

Setup

Tooltip is a component which works on delegation, which means you'll want to specify a *parent* node to work from. Yes, you can use even the body as the parent node, making adding/removing tooltips dynamic and creating the smallest number of event listeners possible. There are four ways you can set up a tooltip.

As Aria-Label

<button class="mk-tt" aria-label="Some text and even markup!">A Tooltip</button>

As Nested Element

<button class="mk-tt">
	<span>A Tooltip</span>
	<span class="mk-tt-modal">A Tooltip Modal!</span>
</button>

As Sibling Element

<div>
	<button class="mk-tt">
		<span>A Tooltip</span>
	</button>
	<div class="mk-tt-modal">A Tooltip Modal!</div>
</div>

Anywhere You Want

This option requires you to 'connect' the tooltip and modal with one another manually with id and aria-describedby attributes.

<!-- some part of the document -->
<button class="mk-tt" aria-describedby="my-tooltip-modal-id">
	<span>A Tooltip</span>
</button>
<!-- some other part of the document -->
<div id="my-tooltip-modal-id" class="mk-tt-modal">A Tooltip Modal!</div>

Instantiation

Remember, Tooltip works on delegation, which is different than our other components. However, instantiation is the same: the first argument being the root, the second being the config options. Config options are opt-in and since Tooltip is a delegate, you'll probably want most of your options set specifically on your tooltip elements. See the Examples Section for more of that. But in case you want to, below are all possible options available to pass in. Additionally, check out the Events Section for adding events to your instance.

var Tooltip = Mk.get('Tooltip');
//
// instantiate
var myTooltip = new Tooltip('body', {
	// set the default position
	// see Examples for all 12 positions
	position: 'top-center',
	// set the delay in milliseconds for mouseover/out tooltips, if any
	delay: 100,
	templates: {
		// change any of the templates for this instance only
	},
	events: {
		..add events here (optional)..
	}
});

Events

All events are part of the Mk EventEmitter and *not* added to the DOM. Events are also called in context of the component instance so it isn't a great idea to use a proxy function to change context, as you'll loose a lot of beneficial object access.

show

Fires when tooltip is shown.


instance.on('show', function (tip, modal) {
	console.info('Showing for:', tip, modal);
});
		

hide

Fired when tooltip is hidden.


instance.on('show', function (tip, modal) {
	console.info('Hiding for:', tip, modal);
});
		

connect

Fired when a connection is being made between a tip and it's modal.


instance.on('connect', function (tip, modal) {
	console.info('Connection being made for:', tip, modal);
});
		

position

Fired when positioning is invoked for a tooltip modal.


instance.on('position', function (tip, modal, coords) {
	console.info('Coors for positioning are:', coords);
});
		

lock

Fires when tooltip is locked or unlocked.


instance.on('lock', function (tip, isLocked) {
	console.info('This tooltip is now ', isLocked && 'locked' || 'unlocked');
});
		

API

Below are the different public properties and methods accessible to you, the end developer. All of these are accessible on your Tooltip [tt] instance as well as inside event handlers bound to your instance. Some methods have intentionally been left out due to their difficulty tof use for end developers vs. internal use.

Methods

  • instance.unmount()

    Teardown instance freeing event, data, and reference memory.

    • No params required.
  • instance.isFocusable(modal)

    Checks modal to see if it has focusable elements or not. Returns boolean.

    Parameters
    • Name
      modal
      Type
      Node
      Description
      Modal element (.mk-tt-modal)
  • instance.link(tip)

    Links a tip element to a modal element.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.position(tip, modal)

    Position a modal to a tip.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
    • Name
      modal
      Type
      Node
      Description
      modal element (.mk-tt-modal)
  • instance.modal(tip)

    Finds the modal associated with the tip.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.show(tip)

    Shows the modal associated with the tip.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.hide(tip[, immediate])

    Hides the modal associated with the tip.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      Tip element (.mk-tt)
    • Name
      immediate
      Type
      Boolean
      Description
      Forces hide without a delay or animation.
  • instance.hideAll()

    Hides all tooltips in the given root context.

    • No params required.
  • instance.toggle(tip)

    Toggles between show() and hide().

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.isOpen(tip)

    Returns boolean value for if the modal is open or not.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.isHidden(tip)

    Returns boolean value for if the modal is hidden or not.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.lock(tip)

    Lock the modal. This diables show() and hide().

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.unlock(tip)

    Unlock the modal. This enables show() and hide().

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.locked(tip)

    Returns boolean value for if the modal is locked or not.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)
  • instance.unlocked(tip)

    Returns boolean value for if the modal is unlocked or not.

    Parameters
    • Name
      tip
      Type
      Node
      Description
      tip element (.mk-tt)

Properties

  • instance.map

    Holds the different calculations used for positioning the tooltip. There are 12 possible positions, each of which can be overriden by you or new positions added to through the config object.