base-ui icon indicating copy to clipboard operation
base-ui copied to clipboard

[all components] Consolidate the `data-open` and `data-presssed `states

Open mnajdova opened this issue 1 year ago • 3 comments

Feature request

Summary

We should use data-open states across different components, and we could use data-pressed vs different state for triggers (tooltip may be a special case)

mnajdova avatar Oct 22 '25 09:10 mnajdova

@mnajdova Wouldn't this cause problems when composing different components, especially triggers?

brianle1301 avatar Oct 26 '25 07:10 brianle1301

i think it would cause some issues,

https://github.com/mui/base-ui/blob/master/packages/react/src/toggle/Toggle.tsx already uses data-pressed to indicate that the button is active. A toggle that opens a menu would be ambiguous - does data-pressed mean button is active or menu is open?

https://github.com/mui/base-ui/blob/master/packages/react/src/tooltip/trigger/TooltipTrigger.tsx opens on hover (not press), so it can't use data-pressed. Without data-popup-open, it has no way to indicate state.

https://github.com/mui/base-ui/blob/master/docs/src/app/(public)/(content)/react/components/menu/demos/submenu/css-modules/index.module.css#L31 use &[data-popup-open]

Raghuboi avatar Oct 27 '25 19:10 Raghuboi

We intentionally had two attributes to separate click vs. hover triggered popups attached to the same element. A common use case is a Tooltip and a Menu attached to the same button. This way you can style each state (hovering into the tooltip) and clicking the Menu differently. e.g. [data-pressed] is darker, while [data-popup-open] matches :hover

atomiks avatar Oct 27 '25 21:10 atomiks