Tooltip: Expose controlled props (open, defaultOpen, onOpenChange) on Root#76931
Tooltip: Expose controlled props (open, defaultOpen, onOpenChange) on Root#76931haqadn wants to merge 1 commit into
Conversation
… Root Widen RootProps to include open, defaultOpen, and onOpenChange from Base UI, enabling consumers to build controlled or click-triggered tooltips. Add a unit test for the controlled open state and a Storybook story demonstrating click-to-toggle usage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @haqadn! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
Can you elaborate on this? What is your specific use case that requires these props to be exposed? I'm not necessarily opposed to exposing those Root props, but I'm also concerned about misuse of the component and want to make sure we're not broadening the API surface for use cases that we're explicitly discouraging in the design system. |
I am trying to workaround a UX issue where clicking the tooltips keeps them closed. A user can think the information icon is supposed to be clicked, and when they do click it, it ends up keeping it closed. Having the API exposed would allow working around this by controlling the behavior without changing the base component. @mirka |
|
@haqadn Tooltips are meant to provide brief, non-interactive hints on hover or focus, and per the WAI-ARIA Authoring Practices, they should dismiss when that state changes. Clicking a button changes the interaction context (often triggering an action or opening another UI), so the tooltip is normally expected to close to avoid stale or conflicting UI. Looking at that example, I'm confused to why we'd expect end users to click on that info icon - isn't hovering enough? |
I think tooltip is right here given the intention. My concern is more about the UX. In the example, the reporter thought the tooltips are broken. Because, they assumed it was supposed to open on click rather than hover. With the APIs open, it would have been possible to tweak the interaction slightly.
That is not the case for the example, so it would have been fine to tweak the behavior a little bit so the tooltip doesn't reset on click. This is what I am trying to do with the exposed API. |
|
Thanks for elaborating @haqadn, it helps for us to understand what developers need from our component set. That is an "infotip" pattern, and I'm hoping to add an official |
The |
|
@haqadn to close the loop:
Hope this can help! |

What?
Expose
open,defaultOpen, andonOpenChangeprops onTooltip.Rootin@wordpress/ui.Why?
Tooltip.Rootcurrently only exposesdisabledandchildrenfrom Base UI'sTooltip.Root.Props, which blocks consumers from building controlled or click-triggered tooltips. Base UI already supports these props and theRootcomponent already spreads all props through, so this is purely a type widening. This follows the same pattern used byAlertDialog.RootandDialog.Rootin this codebase.How?
RootPropsinpackages/ui/src/tooltip/types.tsto pickopen,defaultOpen, andonOpenChangein addition to the existingdisabledandchildren.root.tsxalready spreads all props to the Base UI component.openprop renders the tooltip without hover.ControlledStorybook story demonstrating click-to-toggle usage.Testing Instructions
npm run test:unit packages/ui/src/tooltip— all tests pass, including the new controlled-open test.npx storybook devand navigate to Tooltip > Controlled — clicking the "Toggle tooltip" button should show/hide the tooltip.npx tsc -p packages/ui/tsconfig.json --noEmit.Testing Instructions for Keyboard
Use of AI Tools
This PR was authored with the assistance of Claude Code (Claude Opus 4.6).