PrimeVue 5.0.5 is out, and Tooltip takes up most of it. Tooltips appear on nearly every screen, so this one has to hold steady on pages that re-render often and still reach people who work without a mouse. It went through the component audit after Select, and this release carries the first round of its findings. Select, DataTable and the popup menus get fixes too.

npm install [email protected]

No API is removed. A few Tooltip changes alter what an existing app shows, and the Upgrading section lists them.

Tooltip in the audit

Tooltip scored 49 out of 100 in its first audit round, and two findings marked it as not ready for production, because a basic use broke: an open tooltip disappeared whenever its host re-rendered, and on input components a delayed tooltip could open after the component was gone and stay on the page. The directive did well on idle cost and server rendering. This release fixes both of those findings and adds the first tests for the directive.

A tooltip stays open when its host re-renders

The directive treated every update of its host as a change of its own binding. On each re-render it removed the open tooltip and bound all its listeners again. A tooltip over a button next to a ticking counter closed on every tick, and changing the text from Copy to Copied closed it instead of updating it:

<Button v-tooltip="copied ? 'Copied!' : 'Copy'" icon="pi pi-copy" @click="copy" />

Now the directive compares the new binding with the previous one and does nothing when the value and options are the same. When only the text changed, an open tooltip updates its text and position in place. Measured in a test page with an open tooltip:

Step5.0.45.0.5
Host re-renders, nothing elseclosesstays open
Value changes to 'Copied!'closesstays open, new text

The same check removes the listener churn on unrelated re-renders. With 1000 tooltip targets in one component, one re-render used to remove and add 4000 listeners. It now touches none.

No tooltip is left behind after unmount

InputNumber, Select, DatePicker and the other input components put the tooltip on their inner input. When such a component unmounted during showDelay, the directive canceled the timer on the wrapper, the timer on the input still fired, and a tooltip appeared on the page with nothing to close it, even after the app unmounted. The pending show is now canceled on the element that holds it.

Screen readers hear the tooltip

While a tooltip is shown, its target now carries aria-describedby with the tooltip’s id, so a screen reader announces the text with the target:

<button aria-describedby="pv_id_3_tooltip">Save</button>

<div role="tooltip" id="pv_id_3_tooltip">Save the draft</div>

The id is the one set with the id option when there is one. On input components the attribute goes on the inner input. A target that already has its own aria-describedby keeps it and is not linked to the tooltip. This was primefaces/primevue#5971.

A trigger for hover and focus

The default trigger is hover, which a keyboard user does not reach. The new both trigger shows the tooltip on hover and on focus, keeps it open while the target has focus, and hides it on blur:

<Button v-tooltip.both="'Save the draft'" label="Save" />

The object form of the argument takes the same value, and Dock and SpeedDial take it as tooltipOptions.event:

<Button v-tooltip:[{ event: 'both', position: 'top' }]="'Save the draft'" label="Save" />

Hover stays the default. For keyboard users, set the trigger to both or focus.

Escape and leaving the tooltip

  • Escape closes an open tooltip wherever the focus is. It used to work only on the focused target.
  • With autoHide set to false, moving from the tooltip back to its target closed the tooltip at once, and returning within 50 ms did not reopen it. Leaving the tooltip now waits for hideDelay, and entering the tooltip or the target again cancels the pending hide.
  • Switching the trigger at runtime, for example from hover to focus with a dynamic argument, left the old trigger working. All the listeners of the old trigger are removed now.

Other Tooltip fixes

  • The zIndex.tooltip setting of PrimeVue applied only to components written with the Options API. Components in <script setup> got a fixed value. The setting now applies everywhere, including a value set after the app starts.
  • A number as the value showed nothing, and { value: 5 } threw. Numbers are shown as text, so v-tooltip="0" shows 0.
  • Under a Content Security Policy with require-trusted-types-for 'script', no tooltip opened, because the text path cleared the element with innerHTML = ''. Text is written with textContent now. escape: false still writes HTML, without sanitizing.
  • With reduced motion, the tooltip appears without a fade, and a running fade is canceled when the tooltip hides.
  • Dock and SpeedDial passed only event and position from tooltipOptions to their item tooltips. They pass every option now, so showDelay, class and autoHide take effect.
  • 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.

The directive had no tests. It now has 88, and 52 of them fail when they run against 5.0.4.

Select

  • The selected label disappeared while the filter narrowed the list, and in multiple mode the chips fell back to the raw values. Labels are now looked up in all options, not only the filtered ones.
  • Building the label in multiple mode looked up every selected value with a scan of the whole list. It uses a map from value to option now. With 10,000 options and 200 selected, the scan took about 18 ms on every render.
  • optionGroupChildren given as a function or a dotted path now filters the children of each group.
  • The ARIA position of each option is computed once per list instead of once per row, which grew with the square of the list in grouped lists.
  • With a filter, only one live region announces the result count, and group headers are no longer counted as results.

Other fixes

  • Menu, TieredMenu, Popover, ConfirmPopup and SplitButton close on scroll again after the element they first opened from is removed from the page.
  • DataTable no longer shrinks or sorts a column on a click on its resizer without dragging. In fit mode with a fixed table layout, widths are measured without rounding, so the table no longer gets a horizontal scrollbar.
  • VirtualScroller watches its items by reference and length instead of walking every item on each change. This applies to every component that virtualizes, including Select and DataTable.
  • Gallery with v-model:fullscreen closes from its button and from Escape in browsers without the Fullscreen API.

Upgrading

From any 5.0.x it is a version bump:

npm install [email protected]

Things to check afterwards:

  • A tooltip that relied on a re-render to close stays open. Close it by changing its value or by hiding the target.
  • v-tooltip="0" and other numbers now show the number.
  • Dock and SpeedDial now apply every key of tooltipOptions, so options that were set but ignored take effect.
  • Tooltips in <script setup> components use the configured zIndex.tooltip, so their stacking can change.
  • DataTable column widths, in the DOM and in the saved state, can be fractional pixels.
  • With :fullscreen and no update handler, Gallery’s fullscreen button no longer changes anything. Use v-model:fullscreen.
  • Snapshot tests see the target’s aria-describedby while a tooltip is open.

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