PrimeReact 11.2.3 is out, and most of it is about Tooltip. Much of a tooltip’s work is easy to miss: what a screen reader hears when it opens, and which layer closes first when Escape is pressed. Tooltip came after Select in the component audit, and the first round of findings is in this release. Toast now pulses when the same message is shown again, and Drawer, Sidebar, Tabs and Select have smaller fixes.
npm install [email protected] @primereact/[email protected]
Two changes are visible in an existing app: Escape now goes to the most recently
opened layer, tooltip included, and Tooltip.Root with as renders a real
element. The Upgrading section covers both.
Tooltip in the audit
Tooltip scored 54 of the 65 points measured in its first audit round. The architecture area was not measured in this round, and the React integration area has no ruler yet.
The core flow held up. Open and close delays, moving between tooltips in a
Tooltip.Manager, flipping and shifting near the edges, and server rendering
all worked. The findings were elsewhere: what a screen reader hears, the ways a
tooltip closes, and how long a page with many closed tooltips takes to render.
This release addresses the first two. The cost is unchanged, and the next round
measures it again.
Screen readers hear the tooltip
The popup had no role, no id, and the trigger had no aria-describedby, so
a screen reader announced the button without the text in the tooltip. In
Chromium’s accessibility tree the trigger’s description was empty.
The popup is now a tooltip with an id, and while it is open the trigger points
at it:
<button aria-describedby="pr_id__r_4__tooltip">Save</button>
<div role="tooltip" id="pr_id__r_4__tooltip">Saves the draft</div>
The accessibility tree now gives the trigger its description, and the attribute is removed when the tooltip closes. Nothing changes in the component markup an app writes:
import { Button } from '@primereact/ui/button';
import { Tooltip } from '@primereact/ui/tooltip';
<Tooltip.Root>
<Tooltip.Trigger as={Button}>Save</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Positioner sideOffset={8}>
<Tooltip.Popup>Saves the draft</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
</Tooltip.Root>;
An aria-describedby set on Tooltip.Trigger by the app takes precedence and
replaces the link, so that trigger is described by the app’s element and not by
the tooltip. The same request was open in the v10 repository as
primefaces/primereact#8508.
Escape closes the tooltip wherever focus is
Escape closed a tooltip only when the trigger had focus. A tooltip opened by hovering, while the focus was in a text field, stayed open on Escape. Tooltip now uses the same Escape handling as Dialog and Popover: the most recently opened layer closes first, and focus stays where it was. A tooltip inside a Dialog closes on the first Escape, and the Dialog on the second.
disabled and focus
- Setting
disabledwhile a tooltip was waiting to open did not cancel it, and it opened about 400ms later. Settingdisabledon an open tooltip left it open. Both now close it and cancel the pending open. - After a tooltip was opened by hover and the user clicked elsewhere, moving to the trigger with Tab did not open it. Keyboard focus opens it again.
as on Root and Manager
Tooltip.Root and Tooltip.Manager accepted as, className and style, but
always rendered a fragment, so all three were dropped. With as they now render
that element:
<Tooltip.Root as="div" className="field-hint">
{/* trigger and popup */}
</Tooltip.Root>
Without as they still render no element of their own.
Types and documentation
- The props of
Tooltip.Triggerwere typed as Button props, which suggestedseverityand the other Button props even when the trigger was not a Button. They are typed as the trigger’s own props now. Code that passed Button props still compiles, and withas={Button}those props still reach the Button. - The documentation of
Tooltip.Positionernames'top'as the defaultside, the default the code already used. - A tooltip with
interactivestays open while the pointer is over it, but the links inside it are not reachable with Tab. The documentation now says so and recommends Popover for content that needs the keyboard.
Each fix above has tests.
Toast
Showing a toast again with the id of one that is still open used to update it
quietly. It now restarts the timer and plays a short pulse, so a repeated
message is noticed instead of looking unchanged:
toast.error({ id: 'connection-lost', title: 'Connection lost' });
The toast carries data-repeat, which switches between odd and even on each
repeat, and repeatCount, which counts them. The pulse is skipped when the user
prefers reduced motion. A toast shown again while it is closing comes back after
its exit animation, and toast.update and promise results change the content
without a pulse.
Other fixes
- Drawer and Sidebar close on Escape through the same layer handling, so a
Drawer inside a Dialog closes before the Dialog, and a Select with
closeOnEscape={false}inside a Drawer keeps it open. A Sidebar withcollapsible="none"no longer closes on Escape. - Tabs take the size of the active bar from the active tab, so the bar stays under the tab when the layout resizes.
- Select with a filter moves the focus to the filter when a printable key is typed on the open trigger, and the key reaches the filter. Without a filter, type-ahead works as before.
- Select and AutoComplete options whose value is an object each get their own React key. They all shared one key before, which caused a duplicate key warning.
- Select and Listbox look up the selected labels and the ARIA position of an option without scanning the whole option list each time, which is the slow path for lists with thousands of options.
Upgrading
From any 11.2.x it is a version bump:
npm install [email protected] @primereact/[email protected]
Three things to check afterwards:
- While a tooltip, Dialog, Popover, Drawer or Sidebar is open, Escape closes the
most recently opened one and calls
preventDefault. The event still reaches the page, so an Escape handler of the app can checkevent.defaultPreventedto skip a press that already closed a layer. Tooltip.RootorTooltip.Managerwithasnow renders a wrapper element, which can change the layout around the trigger.- Tests that query by role or snapshot the trigger see the new
role="tooltip", the popupidand the trigger’saria-describedby. A repeated toast carriesdata-repeat.
@primereact/styles 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
PrimeVue 5.0.5 posts cover the Tooltip fixes in the
other two libraries.