-
Notifications
You must be signed in to change notification settings - Fork 17
WComponents toolTip property
The toolTip
property is an optional piece of text which can be used to provide a title
attribute to the component's output element. This is then exposed in some user agents as a hover-effect "tool tip".
Some form control components may be able to use a toolTip
instead of a label if it is impossible to place a WLabel into the UI. If this is the case it will be noted in the documentation for each individual WComponent. This is in line with H65: Using the title attribute to identify form controls when the label element cannot be used.
The use of the toolTip
property is controversial as it may be seen to discriminate against some users. Users who, for example, use a keyboard rather than a mouse but do not use a screen-reader or other assistive technology may not have access to information in a toolTip
. Any information in a toolTip
must, therefore, be available by context to these users. This can make it rather difficult to use a toolTip
.
As a general rule of thumb a toolTip
should not contain information vital to the understanding of the function or use of a control. It should, rather, be used to provide additional context to users who may have trouble determining all aspects of the function by sight.
It is also important to remember that the toolTip may not be available to mobile users.
The tool tip may only be a simple (internationalisable) string with no mark up or extended character entities (such as "
). It is used to set an attribute on a HTML element and should comply with the [restrictions][attribute-restrictions] thereof.
// Given a WComponent (let us assume a WButton)
WButton reloadButton = new WButton("Reload");
// The tooltip can give further context to the button.
givenNameField.setToolTip("Reloads the user details section.");
Some components have special semantics for their toolTip
.
-
WAbbrText uses the toolTip to expose the expansion of the abbreviation.
WAbbrText udhr = new WAbbrText("UDHR"); udhr.setToolTip("Universal Declaration of Human Rights");
-
Components which implement an input pattern (such as WTextField and WMultiTextField) should include a human readable esription of the input pattern in either the WLabel or the components toolTip.
When an input element has a pattern attribute specified, authors should include a title attribute to give a description of the pattern. User agents may use the contents of this attribute, if it is present, when informing the user that the pattern is not matched, or at any other suitable time, such as in a tooltip or read out by assistive technology when the control gains focus.
WTextField constrainedText = new WTextField(); // constrain to a pattern constrainedText.setPattern("[a-zA-Z]{3}[0-9]"); // explain the pattern constrainedText.setToolTip("enter three letters followed a single numeric digit");