Skip to content

WAbbrText

Mark Reeves edited this page Jan 3, 2018 · 16 revisions

WAbbrText is a component used to create abbreviations and acronyms. WAbbrText should be used for the first use of an abbreviation or acronym in any view where that abbreviation may not be familiar to users without expansion. It is optional for other instances of the same abbreviation in the same view or for common abbreviations.

Accessibility

WAbbrText should have a description/expansion text the first time it appears in any view.

The expansion is set using setToolTip(String):

WAbbrText abbr = new WAbbrText("WYSIWYG");
abbr.setToolTip("what you see is what you get");

// or set the expansion in the constructor
WAbbrText abbr = new WAbbrText("WYSIWYG", "what you see is what you get");

Specifying abbreviations

The toolTip property provides the expansion of the abbreviation and must be explicitly specified for each use of WAbbrText. It is output as the title attribute of the abbr element; therefore the toolTip may only contain the expansion of the abbreviation:

The attribute, if specified, must contain an expansion of the abbreviation, and nothing else.
Specification

The toolTip property is limited to simple strings.

WAbbrText udhr = new WAbbrText("UDHR");
udhr.setToolTip("Universal Declaration of Human Rights");

Do not use for dates

It is common to use an abbr element to expand human-readable dates in an unambiguous format. This may harm the accessibility of your application and, therefore, is considered a poor practice; the use of WAbbrText for this purpose is discouraged. Dates should be implemented using WDateField which, when read-only, uses a time element for this purpose.

HTML Output

WAbbrText outputs a HTML abbr element.

Screen shot of a typical use

Screen shot of an abbreviation in a hover state

Where WAbbrText may be used

WAbbrText may be added to any container WComponent without concern for context as WAbbrText always outputs nothing or an element with a content type of phrasing content and is not interactive content.

Example

A simple use of WAbbrText may be as follows in which an abbreviation is added to the content of a WLabel.

WAbbrText abbr = new WAbbrText("CIN", "Customer Identification Number");

WLabel label = new WLabel();
label.add(abbr);

Lists of abbreviations

WAbbrText may get its data from a lookup table for use as a repeated component in WRepeater, a WTableColumn or in WList; or added to a ListLayout. For use in these conditions the methods setTextWithCode and setTextWithDesc are provided to allow the WAbbrText to be populated from a code table. The following snippet shows the use of setTextWithCode on a list of WAbbrText components added to a ListLayout.

// given a table provided through an implementation of
// com.github.bordertech.wcomponents.util.LookupTable by
// com.github.bordertech.wcomponents.util.Factory; and a
// WPanel with a ListLayout:
LookupTable lookup = Factory.newInstance(LookupTable.class);
WAbbrText abbr;

for (Object entry : lookup.getTable("table_name")) {
  abbr = new WAbbrText();
  abbr.setTextWithCode(entry);
  listPanel.add(abbr);
}

Related Components

Further information

Clone this wiki locally