PrimeNG 22.1.5 is out, and most of it is about Tooltip. A tooltip is a small component that shows up on nearly every screen, and when it goes wrong, the people who notice first are the ones using a keyboard or a screen reader. Tooltip followed Select through the component audit, and this release brings the first round of what the audit found. Select, Table, Tabs and a few other components have fixes as well.

npm install [email protected]

A few of the Tooltip changes touch types and pass-through, and the Upgrading section lists them.

Tooltip in the audit

The audit scores a component out of 100 across seven areas, and every point taken off names the finding behind it. Tooltip scored 43 in its first round. Next to other libraries, it did well on life for a tooltip that closes on its own, showOnEllipsis, hideOnEscape, and having pass-through, tokens and unstyled mode together. The findings were about what a screen reader hears, the cost of a hover, and pages with a strict Content Security Policy. All three are fixed here.

Screen readers hear the tooltip

The tooltip container had role="tooltip" but no id, and nothing on the target pointed at it, so a screen reader announced a button without its tooltip. The container now has an id, and while the tooltip is shown the target points at it:

<button pButton pTooltip="Saves the draft" aria-describedby="pn_id_1_tooltip">Save</button>

<div role="tooltip" id="pn_id_1_tooltip">Saves the draft</div>

On a component host such as p-button, the attribute goes on the inner element that takes focus. It is removed when the tooltip hides. A target that already has its own aria-describedby keeps it and is not linked to the tooltip.

Hovering no longer runs change detection

In an app that uses zone.js, every hover over a tooltip host ran change detection 17 or 18 times. The host listeners ran inside the Angular zone, and so did the animation frames of the fade-in, each of which ended in a change detection pass. Measured on one host over five hover cycles:

VersionChange detection runs per hoverOn mouse leave
22.1.417 to 181
22.1.500

On a page with 1000 hosts and a 4x CPU slowdown, the audit measured 77.8 ms of change detection per hover in 22.1.4. The host listeners and the fade now run outside the zone. Zoneless apps were not affected and behave as before.

Trusted Types

Under a Content Security Policy with require-trusted-types-for 'script', no tooltip opened. The default text path cleared the container with innerHTML = '', which Trusted Types rejects, and the error stopped the tooltip. It now clears and writes the text with textContent, so text tooltips work on those pages. This was primefaces/primeng#19054.

escape=false still writes the content as HTML. It does not run under Trusted Types, and it does not sanitize, so it is only safe with content the app controls.

Other Tooltip fixes

  • With tooltipEvent="both", clicking the host closed the tooltip that focus had just opened. It stays open while the host has focus. (primefaces/primeng#17352)

  • A tooltip on a host with no size of its own, such as ScrollTop, was placed against an empty box. It now measures the element that has focus.

  • undefined values in tooltipOptions keep the defaults. Before, an option object with tooltipEvent: undefined turned the tooltip off.

  • The mouse leave listener on the tooltip container is removed when the tooltip hides. Every container used to keep it.

  • With reduced motion, the tooltip appears without a fade, and a fade that is still running is canceled when the tooltip hides.

  • Inside a Dialog, the fade starts when the tooltip becomes visible, so it no longer appears half transparent.

  • A pTooltip on a component such as p-button no longer replaces the component’s own parent instance, so a Badge inside the button finds the button as its parent again.

  • PanelMenu puts the tooltip of an item on the item row, so the tooltip of a parent item no longer opens over its expanded children. (primefaces/primeng#16473)

  • fitContent is part of TooltipOptions, so it can be set in the options object as well as on the input:

    <input pInputText pTooltip="Enter a username" [tooltipOptions]="{ fitContent: false }" />

    (primefaces/primeng#17868)

  • The documentation says that a tooltip with autoHide set to false can be hovered but its content is not reachable with the keyboard, and recommends Popover for content that needs it.

Select

The change event now carries the option that was picked, next to its value:

<p-select [options]="cities" [(ngModel)]="city" optionLabel="name" optionValue="code" (onChange)="onCityChange($event)" />
onCityChange(event: SelectChangeEvent) {
    console.log(event.value); // 'IST'
    console.log(event.option); // { name: 'Istanbul', code: 'IST' }
}

option is null when the value is cleared. Other Select fixes:

  • The selected label stayed hidden while the filter narrowed the list. It stays visible now.
  • A value that matched no option was shown as [object Object]. It shows the value’s label.
  • An editable Select keeps its placeholder, and an empty string counts as no value.
  • The empty message is announced to screen readers when the filter is empty.
  • An option with a null label no longer throws.
  • Finding the selected labels and the group of each option no longer scans the whole list for every value, which is the slow path for lists with thousands of options.

Other fixes

  • Templates with a block at the root, such as an @if around an item, read the template queries once instead of once per row in AutoComplete, InputTags, Listbox, Menu, MultiSelect, OrganizationChart, Select, Timeline and Tree. The same pattern made Table slow in 22.1.3.
  • Listbox, Paginator, Tree and the other components that use ngModel internally threw NG01354 inside a parent <form>. Their internal controls are now standalone.
  • Table no longer sorts or resizes a column on a click on its resizer, and restoring a saved state with an empty filter no longer throws.
  • Tabs move the active bar with the active tab when the layout resizes.
  • A hidden Message gets inert, so its content is not focusable.
  • Gallery moves one image per arrow key press.
  • The Today button of DatePicker moves the calendar to the current month.
  • Scroller in lazy mode starts loading again when the number of items changes, so a Select with a filter loads the filtered items.

Upgrading

From any 22.1.x it is a version bump:

npm install [email protected]

Things to check afterwards:

  • Tooltip types are stricter: tooltipLabel is string | TemplateRef<void>, tooltipZIndex is string | number, and getOption takes a key of TooltipOptions. Code that read these as plain strings, or called getOption with any string, may need a type change.
  • A pass-through function that read parent.instance on a host with pTooltip now gets the host component instead of the Tooltip.
  • styleClass and rootPTClasses on Tooltip are deprecated.
  • Snapshot tests see the tooltip id, the target’s aria-describedby and inert on hidden messages.

PrimeNG requires @primeuix/styles 3.1.1, which a fresh install picks up. The full list is in the changelog. The PrimeVue 5.0.5 and PrimeReact 11.2.3 posts cover the Tooltip fixes in the other two libraries.