Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

refactor(Item, Token, ChatComposer): drop the per-site tooltip surface checks the layer boundary replaces (#9531)

Cindy Zhangb5e716687ca0
diff --git a/.changeset/layer-remove-surface-guards.md b/.changeset/layer-remove-surface-guards.md
new file mode 100644
index 0000000000..b48db54438
--- /dev/null
+++ b/.changeset/layer-remove-surface-guards.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[chore] Item, Token and ChatComposer no longer run their own check for presses inside an open Tooltip or HoverCard; the layer root already keeps those presses from them. No behavior changes.
+
+@cixzhang
diff --git a/docs/specs/components/Tooltip/Tooltip.spec.md b/docs/specs/components/Tooltip/Tooltip.spec.md
index 2afae938ac..52500cb079 100644
--- a/docs/specs/components/Tooltip/Tooltip.spec.md
+++ b/docs/specs/components/Tooltip/Tooltip.spec.md
@@ -116,10 +116,25 @@ in `Tooltip.doc.mjs`.
| rollback | Restore `touchTrigger` and the final-patch `triggerBehavior="adaptive"`, without FR5's walk, from the final-patch baseline |
| state | `pending` — lands in 0.8.0, a declared minor, with its `[breaking]` Changeset |
+### CLN-0028 — Remove the surface registry behind `hasInteractiveAncestor`
+
+| Field | Value |
+| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| id | `CLN-0028` |
+| lifecycle | No deprecation: the next-minor removal of a documented answer that `architecture:layer-runtime` INV17 replaces |
+| delta | The Tooltip and HoverCard surface registry (`Layer/layerSurfacePress.ts`) is removed, and the public `hasInteractiveAncestor` no longer answers true for a press inside an open Tooltip or HoverCard surface; its JSDoc sentence saying so goes with it. INV17 already keeps such a press from every bubble-phase React handler around the layer, so a caller that asks `hasInteractiveAncestor` from a native listener or a capture-phase handler sees a change |
+| rollback | Restore the registry and the JSDoc sentence from the final-patch baseline |
+| state | `pending` — lands in 0.8.0, a declared minor, with its `[breaking]` Changeset |
+
Consumer migration instructions belong in consumer docs and release notes.
## Current-state impact
+- **`hasInteractiveAncestor` still asks the surface registry.** Until the
+ next minor, the public `hasInteractiveAncestor` answers true for a press
+ inside an open Tooltip or HoverCard surface, as its documentation states;
+ Core's own containers rely on `architecture:layer-runtime` INV17 instead.
+ `CLN-0028` removes the registry and that answer.
- **A held-closed tooltip still opens on focus.** With `isOpen={false}`, the
hover path stays shut but any focus FR4 opens on, keyboard focus or a click
into a text-field trigger, opens the tooltip and reports `onOpenChange(true)`, so a caller cannot hold it closed.
diff --git a/packages/core/src/Chat/ChatComposer.tsx b/packages/core/src/Chat/ChatComposer.tsx
index f95a6918e7..1619b92e9e 100644
--- a/packages/core/src/Chat/ChatComposer.tsx
+++ b/packages/core/src/Chat/ChatComposer.tsx
@@ -54,8 +54,6 @@ import {ChatSendButton} from './ChatSendButton';
import {themeProps} from '../utils/themeProps';
import {useAnnounceRenderedText} from '../hooks/useAnnounceRenderedText';
import {useMergedRefs} from '../hooks/useMergedRefs';
-import {innermostInteractive} from '../hooks/useClickableContainer';
-import {isLayerSurface} from '../Layer/layerSurfacePress';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
import {useInteractionModalityTracking} from '../utils/interactionModality';
import {
@@ -439,14 +437,11 @@ export function ChatComposer(props: ChatComposerProps) {
const handleBodyClick = useCallback((e: MouseEvent<HTMLDivElement>) => {
// Focus the input when clicking empty space in the body.
// Skip if the click target is a button, link, or interactive element.
- // A press inside an open Tooltip or HoverCard stays in that surface
- // (component:Tooltip FR11, component:HoverCard FR11).
const target = e.target as HTMLElement;
if (
target.closest(
'button, a, [role="button"], [contenteditable="true"], [data-astryx-token]',
- ) ||
- innermostInteractive(target, e.currentTarget, isLayerSurface) != null
+ )
) {
return;
}
diff --git a/packages/core/src/Item/Item.tsx b/packages/core/src/Item/Item.tsx
index ab3621245e..316a0397a6 100644
--- a/packages/core/src/Item/Item.tsx
+++ b/packages/core/src/Item/Item.tsx
@@ -48,7 +48,6 @@ import {
typeScaleVars,
} from '../theme/tokens.stylex';
import type {BaseProps} from '../BaseProps';
-import {isLayerSurface} from '../Layer/layerSurfacePress';
import {isRenderable} from '../utils/isRenderable';
import {mergeProps} from '../utils/mergeProps';
import {useFocusAcrossSwap} from '../utils/useFocusAcrossSwap';
@@ -57,10 +56,7 @@ import {ItemMarkerColumnsContext} from './ItemMarkerColumnsContext';
import {useMergedRefs} from '../hooks/useMergedRefs';
import {computeTargetAndRel} from '../Link/computeTargetAndRel';
import {useLinkComponent} from '../Link/useLinkComponent';
-import {
- innermostInteractive,
- useClickableContainer,
-} from '../hooks/useClickableContainer';
+import {useClickableContainer} from '../hooks/useClickableContainer';
import {useDevWarning} from '../hooks/useDevWarning';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
@@ -768,12 +764,7 @@ export function Item({
return;
}
const target = e.target as HTMLElement;
- if (
- target.closest('button, a, input, select, textarea') ||
- // A press inside an open Tooltip or HoverCard belongs to it
- // (component:Tooltip FR11, component:HoverCard FR11).
- innermostInteractive(target, e.currentTarget, isLayerSurface) != null
- ) {
+ if (target.closest('button, a, input, select, textarea')) {
return;
}
onClick?.(e);
diff --git a/packages/core/src/Layer/layerSurfacePress.ts b/packages/core/src/Layer/layerSurfacePress.ts
index 758835090f..d66d014b39 100644
--- a/packages/core/src/Layer/layerSurfacePress.ts
+++ b/packages/core/src/Layer/layerSurfacePress.ts
@@ -3,15 +3,11 @@
/**
* @file layerSurfacePress.ts
* @input The content element of an open Tooltip or HoverCard surface.
- * @output A registry of those elements, so the shared "does this press belong
- * to something else" walk (hasInteractiveAncestor) treats a press inside one
- * as not the container's.
- * @position component:Tooltip FR11 and component:HoverCard FR11. The surfaces
- * register their content element; every clickable container that asks
- * hasInteractiveAncestor (useClickableContainer, TreeListItem, Table row
- * plugins), or walks with isLayerSurface (Item, Token), leaves the press
- * alone. The event
- * keeps propagating, so document and window listeners still see it. Not
+ * @output A registry of those elements, read only by the public
+ * hasInteractiveAncestor, whose documentation promises that a press inside
+ * one answers true.
+ * @position Kept until the next minor for that public answer; Core's own
+ * containers rely on layer roots stopping such presses instead. Not
* exported from the package.
*/
diff --git a/packages/core/src/Token/Token.tsx b/packages/core/src/Token/Token.tsx
index 3886c47b60..8ec6d7822b 100644
--- a/packages/core/src/Token/Token.tsx
+++ b/packages/core/src/Token/Token.tsx
@@ -38,9 +38,7 @@ import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
-import {innermostInteractive} from '../hooks/useClickableContainer';
import {usePressFeedback} from '../hooks/usePressFeedback';
-import {isLayerSurface} from '../Layer/layerSurfacePress';
import type {TokenColorMap} from './index';
import {disabledInteractionProps} from '../utils/disabledInteraction';
import {
@@ -497,12 +495,7 @@ export function Token({
if (effectiveOnClick != null) {
const handleContainerClick = (e: React.MouseEvent) => {
const target = e.target as HTMLElement;
- if (
- target.closest('button, a') ||
- // A press inside an open Tooltip or HoverCard belongs to it
- // (component:Tooltip FR11, component:HoverCard FR11).
- innermostInteractive(target, e.currentTarget, isLayerSurface) != null
- ) {
+ if (target.closest('button, a')) {
return;
}
effectiveOnClick(e);
diff --git a/packages/core/src/hooks/useClickableContainer.ts b/packages/core/src/hooks/useClickableContainer.ts
index 03c571b4c4..6d0d4e24e5 100644
--- a/packages/core/src/hooks/useClickableContainer.ts
+++ b/packages/core/src/hooks/useClickableContainer.ts
@@ -111,7 +111,9 @@ export function hasInteractiveAncestor(el: Element, rootEl: Element): boolean {
return innermostInteractive(el, rootEl, belongsToSomethingElse) != null;
}
-// A press inside an open Tooltip or HoverCard surface belongs to that surface.
+// hasInteractiveAncestor documents this answer until the next minor.
+// A layer root stops such a press before any bubble-phase React handler.
+// A native listener or a capture-phase handler still sees it.
function belongsToSomethingElse(element: Element): boolean {
return matchesInteractiveSelectors(element) || isLayerSurface(element);
}