type: widget
release: TBD
status: in development - GitHub branch: tooltip
documentation: n/a
discussion: http://forum.jquery.com/tag/jquery-ui-tooltip
demo: http://view.jqueryui.com/tooltip/demos/tooltip/default.html
1 - Description:
A tooltip is a small overlay that sits over the main page that can be used to provide content or functionality that does not need to be always visible. Tooltips usually look like a small box or callout and can be trigged by a wide range of events. All tooltips should employ collision detection via the the Position utility and iframe protection via the bgiframe plugin.
- General
- All tooltips should be automatically protected by the bgiframe plugin to avoid z-index issues
- The tooltip body should automatically expand to the width and height of the content
- Maximum width option may need to be set in the CSS to keep tooltips from getting incredibly wide, you want it to wrap at some reasonable width (200-400px)
- This could be a problem in IE6 as there is no max-width support. CSS Expressions as an alternative?
- Maximum height option (scrollbars should appear if content height exceeds tooltip height)
- Content
- The native browser tooltip is always suppressed.
- If no content is specified, the tooltip will grab the title attribute from the element and display the title content unformatted.
- The content can be a string, including HTML markup, that will replace the title attribute
- The content can be a function that either returns the HTML markup to display, or uses the provided callback to get asynchronous content (eg. via Ajax)
- M1 Simple tooltip
- This tooltip is used strictly for non-interactive content such as descriptions and text strings which cannot be directly interacted with by the end-user.
- Default settings:
- Show on mouseenter, delayed by 150ms (configurable, could use hoverintent for more intelligent behaviour)
- Hide on mouseleave
- Animations
- Animations for the show and hide events should be optional to allow the tooltip to use any of the standard jQuery UI animated transition effects.
- Defaults:
- Show: fade effect
- Hide: fade effect
- Positioning
- Relative to the cursor position
- Static position: position tooltip based on position of cursor when called, do not re-position tooltip unless closed and re-opened (default)
- Follow cursor position: constantly re-position tooltip as the cursor moves
- Relative to the element
- Can use any of the position placements: ex. left aligned and above parent; at the far right end of parent, above and to the right
- Visual styles
- The tooltip should be completely compatible with the CSS framework and Themeroller, including the connector graphic
- Any custom class name including other framework container classes should be an optional parameter
- widget-header, widget-content, state-default, state-hover, state-active, state-highlight, state-error can be passed in as an option so the tooltip can have different, themed styles
- The option to add in the shadow class (when complete) would be a good option
- Callout connector (Tip)
- Created using polygonal CSS (http://www.filamentgroup.com/lab/image_free_css_tooltip_pointers_a_use_for_polygonal_css/) or Canvas/VML implementation. Or even a combination of both.
- By default, it should have the ui-widget-content class
- No callout connector: simple rectangular tooltip
- Callout connector triangle: In two variants, filled and unfilled connectors
- For any of these styles, the connector (if present) can appear in any of the standard 12 positions around the perimeter of the tooltip body:
- Top edge, left aligned
- Top edge, center aligned
- Top edge, right aligned
- Left edge, top aligned
- Left edge, middle aligned
- Left edge, bottom aligned
- Right edge, top aligned
- Right edge, middle aligned
- Right edge, bottom aligned
- Bottom edge, left aligned
- Bottom edge, center aligned
- Bottom edge, right aligned
- A labs experiment for more accurate positioning: http://jquery-ui.googlecode.com/svn/branches/labs/tooltip-callout/index.html
- Accessibility
- The tooltip must be fully accessible (ARIA) and should provide update announcements to screenreaders to ensure that the tooltip content is read correctly when activated
2 - Visual Design:

3 - Functional Specifications/Requirements:
Options:
- content (String, Function, default: function that returns the title attribute)
- The content of the tooltip, as HTML, returned by a function that will either
- return the content to display
- call another callback (passed as the first argument) with the content to display, to enable asynchronous operations
- This is the right place to format the tooltip by adding elements (with extra classes) or any other changes
- position (Options, default: { my: "left top", at: "left bottom", offset: "15 0" })
- Configuration for the Position utility, of option excluded (always configured by widget)
- tooltipClass (String, default: "ui-widget-content")
- additional classes to put on the tooltip
- can be CSS framework classes like ui-widget-header, ui-widget-content, ui-state-default, ui-state-hover, ui-state-active, ui-state-highlight, ui-state-error
Methods:
- open
- Programmatically open the tooltip, use close method to close it again
- close
- Programmatically close the tooltip, use open method to open it again
Events:
- open
- triggered whenever the tooltip is shown
- close
- triggered whenever the tooltip is hidden
4 - Markup & Style:
4.1 Initial markup examples
(Pre-enhanced HTML markup structure that will be transformed into the final widget. There may be multiple possible HTML markup options per widget: for example, for a slider, radiobuttons, inputs or selects could all be used. )
4.2 Recommended transformed HTML markup
(The HTML markup structure and classes that will be used by the scripts in the enhanced version)
4.3 Accessibility recommendation
When removing the title-attribute from an element, add a "aria-describedby" attribute with the value referencing the id of the tooltip-element.
element.removeAttr("title").attr("aria-describedby", tooltipId);
The aria-describedby attribute needs also be added to input elements, when the label provides the tooltip.
This also requires the body to have a role="application" - where should that be handled?
The tooltip element needs .attr("role", "tooltip")
When hiding the tooltip, use .attr("aria-hidden", true), when showing it, use .attr("aria-hidden", false)
4.4 CSS & Theme
(Description of the CSS classes to be used for all states, how custom theming and Themeroller support will work.)
5 - Latest version of plugin:
http://view.jqueryui.com/tooltip/tests/visual/tooltip/tooltip.html
6 - Open issues
Italics means we'll ignore those issues for a first release. We need more information, context, experience or usecases to properly solve them.
While sticky tooltips are still described, we currently don't plan to implement them, as their interaction is too close to a dialog while lacking the proper interactions, eg. ESC to close wouldn't make sense for a tooltip. We may get back to this eventually.
Connectors aren't implemented, yet. There are various approaches and none are really satisfying so far. Some resources:
Currently jquery.ui.tooltip.css defines a z-index of 999 for tooltips. There was a comment about this posing problems with Tabs (unable to reproduce those, see tests/visual/compound/tabs_tooltips.html ), so it may make sense to rethink that value. Though it can be easily fixed once we actually have more data on that issue.
Position issue:
http://forum.jquery.com/topic/tooltip-1-9m1-position-issue
caused by position, related to offset issue in jQuery core
http://dev.jquery.com/ticket/6483
How to handle tooltip width:
- Don't restrict at all, just let the tooltip grow based on content
- works for normal title-lengths
- can get very big for long texts
- makes it trivial to define in CSS (no override necessary)
- could also be set in open-event when the content is present, to calculate something
- Set a fixed width in theme
- avoids tooltips getting too large
- has to be overriden
- usually either too big or too small, doesn't adapt to content
- Set max-width in theme
- anything smaller adapts to content
- no/bad IE6 support
- text-wrapping rather arbitrary, will probably look bad in a lot of cases when content is wider then the default max-width
How existing plugins handle it:
- Jörn's tooltip doesn't specify a width, by default; user has to fix that where necessary, no known/reported issues with that
- clueTip and qTip both set width via JavaScript as inline styles, not something we want to do; at least qTip has also min/max width options, probably also for height
Comments (20)
fnagel said
at 10:53 am on Jan 28, 2010
I tried to integrate this tooltip into my accessible form validation widget and must confess this plugin breaks ui.position by using hide().
See http://www.felixnagel.com/fileadmin/downloads/Formular.zip for a demo. Just try to check a one selectbox, then go to tooltips.js and comment hide() out. Now it works.
fnagel said
at 11:22 am on Jan 28, 2010
This _init method works for me. _init: function() {
var self = this;
this.tooltip = $("<div></div>")
.attr("id", "ui-tooltip-" + increments++)
.attr("role", "tooltip")
.attr("aria-hidden", "true")
.addClass("ui-tooltip ui-widget ui-corner-all")
.addClass(this.options.tooltipClass)
.appendTo(document.body);
this.opacity = this.tooltip.css("opacity");
this.tooltip.css("opacity", 0);
this.tooltipContent = $("<div></div>")
.addClass("ui-tooltip-content")
.appendTo(this.tooltip);
if (!this.options.noHover)
this.element
.bind("focus.tooltip mouseover.tooltip", function(event) {
self.show($(event.target));
})
.bind("blur.tooltip mouseout.tooltip", function(event) {
self.close();
});
},
Jörn Zaefferer said
at 4:20 pm on Mar 25, 2010
Any idea about the difference between display:none and opacity:0? Does this still happen for the current version? (See the top of the wiki page for the github branch link)
fnagel said
at 7:53 am on Apr 12, 2010
I tested the new svn version, same problem. I will post a link to you changed script in a few days, im about to update my repo (old version still online: http://fnagel.github.com/jQuery-Accessible-RIA/Formular/custom-error.html)
DaVinci007 said
at 2:01 pm on Mar 31, 2010
Hi, this is my first post so I would first like to say hi to all the hard workers here. You are doing a great job.
Concerning the callout connector, there has been a few dicussions on what should be used to draw the triangles and rounded corners. I have come into excanvas for other purposes and would like to point out it could be considered. It adds canvas support to IE6+ using IE's VML.
Main project: http://code.google.com/p/explorercanvas/
As jquery plugin: http://code.google.com/p/jqcanvas/
Wichert Akkerman said
at 2:38 pm on Mar 31, 2010
I have used explorercanvas in two projects, but found it to be effectively unmaintained, and broken on current patchlevels of IE. I strongly recommend not to use it for any jquery ui widget.
p3go83 said
at 1:33 am on Apr 12, 2010
Hi to all!
I've developed a version based upon the github branch and the filament group's callout connector (Tip): here my version with a little demo (themeroller enabled):
http://depositfiles.com/files/anwrykwlf
added 3 options:
- delay: 150,
- connector: "unfilled", //filled, unfilled, none
- connectorPosition: "left middle"
2 points to solve:
- in IE the render of connector in not so beautiful...
- in IE the fade animation is horrible, in my code I've used hide()/show() instead
one more thing: imho using the position plugin is too difficult for beginners: perhaps is better to calculate it based on the position of the connector.
Any comments/ideas are appreciated
(sorry for my english...)
fnagel said
at 7:42 am on Apr 12, 2010
// role=application on body required for screenreaders to correctly interpret aria attributes
if( !$(document.body).is('[role]') ){
$(document.body).attr('role','application');
}
Could you please provide some further information to this issue? Would be interesting for my own widgets too.
Thanks in advance, Felix
Jörn Zaefferer said
at 7:46 am on Apr 12, 2010
The code is based on the recommendation in FGs new book about progressive enhancement. After some discussions on the jquery-a11y group, we may have to remove this, though. I'm waiting for a clarification that FG wanted to get from their technical editor.
fnagel said
at 1:38 am on Apr 13, 2010
Mhh i wrote my master thesis about accessibility in FE (ARIA and WCAG 2.0) -- never heard of AT needs a role to interpret aria. I will ask some of my Accessibility buddies...
... would you tell me what FG is?
Jörn Zaefferer said
at 1:41 am on Apr 13, 2010
FG is Filament Group, their new book is Designing with Progressive Enhancement, their technical editor is James Craig, lead of the W3C WAI-ARIA spec.
Aaron Barker said
at 9:17 am on May 10, 2010
The example in section 5 ("Latest version of plugin") has positioning issues if you scroll the element to the bottom. The tooltips for the buttons show up above the first name field (FF/Chrome on Mac). This issue isn't apparent when opening in a new window, but the plugin should probably accommodate the tooltips being in a scrollable element.
Motty said
at 2:12 am on May 13, 2010
Any chance we could have the option to hook the tooltip using live events as well as regular events? There are a limited number of tooltips that have this feature, and work well. Thanks!
Richard D. Worth said
at 3:08 am on May 13, 2010
Do you mean live or livequery? You have to initialize the tooltip widget on the element. If the element doesn't exist yet but will later, .live() [1] won't help with that, but .livequery() [2] would.
There's currently no plan to build in support for livequery, that I know of. But you can certainly use livequery yourself to automatically initialize tooltips on elements as they're added in the future:
$(selector).livequery(function() {
$(this).tooltip();
});
http://jsbin.com/awode3
---
[1] .live() - http://api.jquery.com/live/
[2] .livequery() - http://brandonaaron.net/code/livequery/docs
Motty said
at 7:27 am on May 13, 2010
Thanks for the quick reply, oddly it does seem to work (on the second pass) with .live() - http://jsbin.com/awode3/2/edit
Richard D. Worth said
at 7:29 am on May 13, 2010
Yeah, that makes sense. You're doing an init on mouseover which binds to mouseover, so it doesn't function until you out and over again. That's why you need to init before that first mouseover.
Ralph Whitbeck said
at 9:38 am on May 25, 2010
Can I suggest that the content option be allowed to return a jQuery Object?
So I'd like to do something like this:
$("a").tooltip({
content: function() {
return $("<img />").attr("src", "http://somedomain.com/images/file.jpg");
}
});
I was able to accomplish it in this example http://jsbin.com/abego by appending it to a div fragment and then returning the div's html but it would be alot easier if I can just return a jQuery object that can get appended to or replace the tooltip's content.
Pierre.H A said
at 12:35 pm on Jun 11, 2010
Hello,
Their is a very good notification plug-in witch support (more or less) the jQuery UI CSS Framework !
You should take a look : http://www.stanlemon.net/projects/jgrowl.html
jGrowl have a lot off very interesting functionalities, i would sugest people to download the package . It contains very insteresting examples ;)
Richard D. Worth said
at 2:48 am on Jun 16, 2010
From http://forum.jquery.com/topic/tooltip-with-connectors-arrow-pointer salesking says "I saw the page here http://wiki.jqueryui.com/Tooltip and build something else => http://github.com/salesking/king_tour from which parts/ideas might be taken to build the missing connectors/pointer/arrows
my solution is by far perfekt and the use-case might be different but the tooltips can be positioned pretty versatile and the arrows are css only with outer borders.
See the tooltip positioning with arrows here:
http://salesking.github.com/king_tour/ => positioning tour"
aurelien gerits said
at 1:19 pm on Jul 6, 2010
To have html content in a title attribute and return the contents with tooltip
function t_content(element){
var attitle = $(element).attr("title");
return $("<div><span style='float:left;' class='ui-icon ui-icon-info'></span> "+attitle+"</div>");
}
/**
* Initialisation javascript pour les formulaires
*/
$(function() {
$("[title]").tooltip({
tooltipClass: 'ui-state-highlight',
content: function() {
return t_content(this);
}
});
});
Great ;-)
You don't have permission to comment on this page.