J4.x

J4.x:Joomla 4 Tips and Tricks: Titles and Tooltips

From Joomla! Documentation

Revision as of 06:22, 15 May 2021 by Ceford (talk | contribs) (First pass)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Under Construction

This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.
This article was last edited by Ceford (talk| contribs) 5 years ago. (Purge)


Introduction

As a developer you will have met title attributes, tooltips and popovers intended to provide extra information needed to carry out some task. You may also know that you Joomla has a Tooltip design a little different from the Bootstrap design. But what should you use where, or not at all?

Articles to read:

The title attribute

The title attribute can be applied to almost any html element and has been widely used and abused for years. It contains text representing advisory information related to the element it belongs to. On hover, the browser shows the element title text after a short delay. The default browser title display is small, bland and unobtrusive. That leads developers to style their title attributes to produce what are commonly known as tooltips, which might be big and brash.

Title attributes are most commonly used for links, buttons and form input elements. These are navigational elements which obtain focus in turn, usually with repeated use of the Tab key. The title might say what sort of input is expected or what a link or button will do. It is commonly used where space for explanatory text is limited, sometimes to the extent that icons are used instead of words.

Best advice: do not use the title attribute unless you really have to. If at all possible, redesign the page to make titles unnecessary. Ask yourself what the title is supposed to do, what you expect a sighted person to see and what do you expect a non-sighted person to hear with a screen reader. This is designing for accessibility. Remember that a non-sighted person might be tabbing through focusable elements and listening to what they do. A sequence of Click here or Read more is not going to be very helpful.

Examples from Joomla 4 Beta8-Dev

Go to the Administrator Articles list. Almost all of the Joomla list pages work the same way so you could choose almost any page.

Article Title

Hover over any title link for any article. After a short pause a small bland label appears with the text Edit [article title]. It is trying to tell you that selecting this link will take you to the article edit page. You can tell from the nature of the label that it is implemented as a title attribute of the <a> tag. Try navigating to a link with the keyboard - the label does not appear. Is this title really worth it. Someone must have thought so during the page design stage.

The HTML code for this table cell is rendered as follows (layout revised for easy reading):

<div class="break-word">
	<a href="/j4test/administrator/index.php?option=com_content&amp;task=article.edit&amp;id=27" 
		title="Edit Queen Elizabeth II"
	>
		Queen Elizabeth II
	</a>
	<div class="small break-word">
		Alias: queen-elizabeth-ii
	</div>
	<div class="small">
		Category: 
		<a 
			href="/j4test/administrator/index.php?option=com_categories&amp;task=category.edit&amp;id=18&amp;extension=com_content" 
			title="Edit Category"
		>
			Monarchs
		</a>
	</div>
</div>

Screen Reader

The following image shows the page with a screen reader turned on. The selected field is outlined in orange.

Title in Screen Reader Example

And it says, in transcript: Queen Elizabeth the second [pause] Link

So no mention of Edit or what the link is to. Could this be made more useful to the non-sighted? Is the title attribute doing anything useful for the normally sighted?

Search Tooltip

Hover over the Search field - a Tooltip appears. Hover elsewhere - the Tooltip disappears. Click on the field or tab to the field - the Tooltip appears but does not disappear when the hover is moved away. It needs the focus to move away to disappear.

The Tooltip content is quite complicated with several different prefixes you can use to search different fields. Clearly, this one would be difficult to fit into available space without completely redesigning the filter. Almost all of the component list pages use this search bar layout so a Tooltip does seem appropriate.

The rendered HTML code laid out to help understanding:

<div class="btn-group">
	<div class="input-group">
		<input 
			type="text" 
			name="filter[search]" 
			id="filter_search" 
			value="" 
			class="form-control" 
			aria-describedby="filter[search]-desc" 
			placeholder="Search" 
			inputmode="search"
		>
		<div role="tooltip" id="filter[search]-desc">
			Search in title, alias and note. Prefix with ID: or AUTHOR: or CONTENT: to search for an article ID, article author or search in article content.
		</div>
		<span class="visually-hidden">
			<label id="filter_search-lbl" for="filter_search">
				Search Articles
			</label>
		</span>
		<button type="submit" class="btn btn-primary" aria-label="Search">
			<span class="icon-search" aria-hidden="true"></span>
		</button>
	</div>
</div>

Remember that in the real source code strings in English here will appear as Text::_('...') values.

Screen Reader

The screen reader only responds to change in focus, so on tabbing to this field with the keyboard it says, in transcript:

Section search [pause] Edit text [pause] Search articles with hid search [pause] Search in title [pause] alias and note [pause] Prefix with ID: or AUTHOR: or CONTENT: to search for an article ID [pause] article author or search in article content

Notice that the pauses occur at commas and full stops. So some improvement for both sighted and non-sighted is possible:

Search in title or alias or note. Prefix with ID: to search for an article ID, or AUTHOR: to search for an author, or CONTENT: to search in article content.

Parent Links

Back to J4.x:Tips and Tricks for Joomla 4 Developers