Repository navigation
[popups] Apply the same open-change rules to every popup - #6111
Conversation
commit: |
Bundle size
PerformanceNo regressions in 36 benchmarks · ran 4m 02s · details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
13fdca3 to
bc642cb
Compare
PR reviewNothing blocks merging. Two independent bug passes found no 🔴 regressions. They traced every removed per-component override back to the shared store and checked the drop rule against controlled popups, exit animations, focus return and the Tooltip delay group. There is one real regression. For Dialog, AlertDialog and Drawer, a Bugs (2)1. 🟠 A later close cancels an earlier close's
|
… unmount requests
…skip detached close triggers
… shown, and filter detached triggers for Menu too
…x unmount requests
…a close names the active trigger
…o another trigger
39fae2c to
6d4bc01
Compare
…eScript handbook pages (#343) ## Why - Four handbook pages (Styling, Composition, Customization, TypeScript) have no family. The parity page thus cannot show a Base UI change of those pages as mirrored or queued. - [Base UI #6215](mui/base-ui#6215) changes only the Customization page. The parity page shows it as `not started`, although the page exists. ## What - Adds the families `handbook-styling`, `handbook-composition`, `handbook-customization` and `handbook-typescript`. Each family names the folder of its Base UI page in `upstreamPaths`. Each has an extract at the tracked Base UI commit. - Customization page: the paragraph after the `preventVaseUIHandler()` sample now says that the listener takes over the interaction. It links to the sections on controlled state and on `cancel()` ([Base UI #6215](mui/base-ui#6215)). It replaces the "escape hatch" sentence. - Customization page: a new paragraph says that `cancel()` is the way to decline a change of a controlled part. A request that the `open` prop does not follow stays pending, so the part still reports a later close ([Base UI #6111](mui/base-ui#6111)). These cases show it: - `packages/vue/src/menu/root/MenuRoot.test.tsx`, "open change requests": the part reports a close after a declined hover open, and reports no close after a canceled hover open. - `packages/vue/src/select/root/SelectRoot.test.tsx`, "closing": the part reports a close after a declined open. - `packages/vue/src/utils/popups/popupRoot.test.tsx`: "follows the open prop, and keeps the popup open when the parent declines a request". - `CONTRIBUTING.md`: each handbook page has a family. A family with no Base UI demos has no record, so do not run `pnpm docs:demos` for it. Compare the page with the Base UI page before you move `matchedCommit`. - The Styling, Composition and TypeScript pages have no change. Each page has the blocks of its Base UI page in their Vue form, with two exceptions: - The CSS-in-JS sample of Styling is reduced. It uses `MenuPositionerCssVariables` in a `style` binding, and not `MenuItemDataAttributes`. A `style` binding has no selector, and the docs package has no CSS-in-JS library. - The Composition page has no sentence on performance. A `#render` slot is not a faster form of `as`, because both get their props from the same function. ## Tests - `pnpm parity:check` passes with the four new families. Each has no source, no case and no exception row. - The built parity page shows `handbook-customization: mirrored` for Base UI #6215. No change has the state `not started`. Before this change, Base UI #6215 was `not started`. - `pnpm docs:build` passes. The two new links of the Customization page resolve to headings of that page. - `pnpm lint`, `pnpm build` and `pnpm docs:typecheck` pass. - Each of the four pages was read against its Base UI page at the tracked commit, block by block. - The pull request adds no test: it changes data and text. - `pnpm parity:check` already fails when an extract is absent, and when `matchedCommit` is not the commit of the extract. `pnpm test:docs` already fails when a family has a folder in `docs/demos` and no record.
Master (mui#5960, mui#6111) moved `useOpenStateTransitions` into popupRoot.tsx and replaced its `onUnmount` callback with the store's `resetOnUnmount`. Ported the deferred close check there: when an open request is pending at unmount, `resetOnUnmount` and `onOpenChangeComplete(false)` now wait until the request turns out to be ignored, and are skipped if it reopens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every popup Root now follows the same open-change rules. The shared store already ran one sequence for every popup, but some stores still overrode steps of it in ways that their interactions didn't need.
Problem
BasePopupStore.setOpenruns every open change in one order: guards,onOpenChange, stop if canceled, notify the interactions, then commit in one update. Several stores drifted from that order or from each other:clickthat some mobile browsers fire after a focus-open, but only afteronOpenChangeand the interactions had heard about it. A controlled menu closed on a tap it meant to ignore.instantTypein a second update, so a hover open rendered once with the previousdata-instant.preventUnmountOnClose()to the store as soon as it was called, even for a canceled close, so the next close never unmounted. The other popups dropped a canceled close's request but ignored a call made after anawait.Popover.Close, or always.Changes for users
No API changes, but two parts of the
onOpenChangecontract change: it's no longer called for a close while the popup is already closed, andeventDetails.triggeris now set for closes that name no trigger. UseeventDetails.reasonto tell close causes apart.clickright after a focus-openonOpenChange(false)is called and the menu closespreventUnmountOnClose()thencancel(), followed by a normal closepreventUnmountOnClose()called after anawaitinonOpenChangepreventUnmountOnClose()on a close the parent declined withoutcancel(), followed by a close that doesn't call itcancel()onOpenChangefor a close while the popup is closed, such asactions.close()orhandle.close(), leaving a Tooltip trigger before its delay ends, or the delay group closing a tooltip that is already closing (Popover, the Dialog family, Tooltip, Preview Card, Select)eventDetails.triggerfor an Escape, outside press or other close that names no trigger (Popover, Tooltip, Preview Card, Select, Combobox)undefined, or for Popover the active trigger withPopover.Closeonlyactions.close()while a hover open is pendingcancel()data-instant="dismiss"instantTypeChanges
BasePopupStoredrops a close request when both the store's last request and theopenprop say the popup is closed.onOpenChangedoesn't hear about it and noopenchangeis emitted, but the hover interaction still cancels a pending hover open. A change a store won't commit belongs inisOpenChangeIgnored, which runs beforeonOpenChange.isOpenChangeIgnored, and theisOpenChangeDroppedstep is gone.instantTypefromprepareOpenChange, and thecompleteOpenChangestep is gone.preventUnmountOnClose()is handled once inBasePopupStore. A call made duringonOpenChangeis committed with the close. A call made after the commit applies until the popup opens again, even if more closes commit in the meantime, and a call on an open change or a canceled close is ignored. The request lasts until the next open, as it already did for every popup but Select and Combobox, so a parent declines a close withcancel(). Dialog's andValuePopupStore's overrides are removed.TooltipStore.closeForSiblinggives the delay group its own call. It closes an open tooltip. For a tooltip that is already closing, it stops hover tracking and marks the tooltip soTooltip.Rootskips the rest of its exit.getCloseTriggerreports the active trigger, andsetOpenleaves out a trigger that has left the document. Popover's and Dialog's overrides are removed. Menu keeps its own, which reads what the Root last rendered.actions.close()while closed is removed, since the shared store covers it.flushSync. The other popups need the synchronous commit for nested hover popups.Fixes #6041