Skip to content

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

TypeScript

fix(layer): reset text and whole surface membership (#6457)

Cindy Zhang4ec26d75769d
diff --git a/.changeset/layer-text-boundary.md b/.changeset/layer-text-boundary.md
new file mode 100644
index 0000000000..014c7557c1
--- /dev/null
+++ b/.changeset/layer-text-boundary.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': minor
+---
+
+[breaking] Layer content starts with theme body typography and neutral text formatting. Core layers end ancestor React surface/group membership as a whole, including group-owned disabled state, selection, callbacks, and label associations. Place intentional groups and complete required providers inside the layer. Unrelated contexts, explicitly authored props, themes, and styling overrides remain unchanged. Structural CSS isolation is incomplete: layers opened from Step content can still pass an outer `--step-connector-gap` to an inner Stepper. Lab Drawer receives the text baseline but retains ancestor React provider inheritance.
+@cixzhang
diff --git a/docs/architecture/layer-runtime.md b/docs/architecture/layer-runtime.md
index 7ebd388728..50e3910cf1 100644
--- a/docs/architecture/layer-runtime.md
+++ b/docs/architecture/layer-runtime.md
@@ -37,7 +37,7 @@ verified_by:
packages/core/src/hooks/useMenuHover.test.tsx,
packages/core/src/Toast/ToastViewport.test.tsx,
]
-deciding_specs: []
+deciding_specs: [spec:AST-038]
---
# Layer runtime
@@ -188,6 +188,47 @@ and swipe paths do not use it. There is no shared interaction-owner role,
association graph, branch registry, or outside-branch resolution operation on
current `main`.
+### Layer content boundary — AST-038 implementation projection
+
+[AST-038](../specs/AST-038-layer-text-boundary/spec.md) owns the reading baseline
+and surface/group boundary. This implementation resets layer-root text and whole
+React contexts carrying surface/group membership; structural CSS isolation is
+incomplete.
+
+The shared private text baseline is applied in both `useLayer` renderers and the
+Dialog, Lightbox, MobileNav, BottomSheetPanel, and ToastViewport content roots.
+Component and caller styling remains stronger. Existing padding normalization,
+hosting, theme inheritance, and writing context remain unchanged.
+
+`createLayerScopedContext` creates surface-scoped contexts whose complete default
+value is provided by `LayerContentBoundary`. Membership-owned disabled state,
+selection, callbacks, and labels stop together with presentation defaults.
+Existing context shapes and public hooks are unchanged. Content-local providers
+remain owners; consumers requiring a group need its complete provider inside the
+new surface. Menus already establish their own content-local owner and close
+chain. Unrelated application state, collection protocols, semantic DOM selection,
+and interaction coordination continue through ordinary React contexts.
+
+Each boundary snapshots its provider chain at mount so later lazy imports cannot
+remount live content or discard state/focus. Existing native depth-provider seams
+retain their original depth values; raw Layer, sheet panels, and toast content
+use the private content boundary directly. Toast page children stay outside it.
+
+Lab Drawer uses the equivalent package-local text baseline and retains its
+existing hosting, dismissal depth, and ancestor React contexts. Whole-context
+isolation for Drawer is not implemented: the private Core boundary is not
+available across that package boundary. This is a remaining package-architecture
+gap, not a claim of complete provider isolation.
+
+Structural custom-property channels remain outside this implementation. A layer
+opened from supported `Step.children` content can contain an inner Stepper that
+still inherits the outer `--step-connector-gap`. React membership ends, but this
+connector-layout inheritance remains a structural isolation gap.
+
+Existing component behavior checks cover membership exit, explicit inner owners,
+unrelated context continuity, and state/focus retention. Browser evidence covers
+text inheritance and visual appearance.
+
### Current global and nonparticipating surfaces
LayerProvider supplies Toast configuration and mounts ToastViewport. It is not a
@@ -320,7 +361,8 @@ be updated only as that work ships.
## Deciding specs
-No system spec changes the shipped runtime described here.
+`spec:AST-038` governs the layer content boundary projected above. It does not
+change the hosting runtime described here.
`spec:AST-003` is accepted but unimplemented. It defines the approved next
runtime and must move to `shipped` before its requirements are incorporated into
diff --git a/internal/vibe-tests/setup-test/setup-canonical.test.ts b/internal/vibe-tests/setup-test/setup-canonical.test.ts
index 0456003af4..7c97e19820 100644
--- a/internal/vibe-tests/setup-test/setup-canonical.test.ts
+++ b/internal/vibe-tests/setup-test/setup-canonical.test.ts
@@ -654,9 +654,12 @@ function applyEnterpriseComposition(arm: string) {
if (start === -1 || end === -1) {
throw new Error('canonical enterprise dialog edit did not apply');
}
+ // AST-038 makes inherited typography an explicit root-level choice. This
+ // host-owned composition deliberately keeps its established host type.
next = `${next.slice(0, start)} {dialogOpen ? (
<Dialog
aria-labelledby="service-dialog-title"
+ style={{fontFamily: 'inherit', fontSize: 'inherit', lineHeight: 'inherit'}}
className="fixture-shell block z-[50] rounded-lg border border-border bg-panel p-6 text-foreground shadow-2xl"
data-guest-design-system
data-mode={mode}
diff --git a/packages/core/src/Avatar/AvatarSizeContext.ts b/packages/core/src/Avatar/AvatarSizeContext.ts
index ce163b7f81..5b3fa3fc7a 100644
--- a/packages/core/src/Avatar/AvatarSizeContext.ts
+++ b/packages/core/src/Avatar/AvatarSizeContext.ts
@@ -4,7 +4,7 @@
/**
* @file AvatarSizeContext.ts
- * @input Uses React createContext
+ * @input Layer-scoped React context
* @output Exports AvatarSizeContext
* @position Internal context; provided by Avatar, consumed by sub-components
*
@@ -12,7 +12,7 @@
* - /packages/core/src/Avatar/Avatar.doc.mjs
*/
-import {createContext} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
/**
* Context that provides the resolved numeric avatar size (in pixels)
diff --git a/packages/core/src/AvatarGroup/AvatarGroupContext.ts b/packages/core/src/AvatarGroup/AvatarGroupContext.ts
index 8380f8b430..f6dae5f00d 100644
--- a/packages/core/src/AvatarGroup/AvatarGroupContext.ts
+++ b/packages/core/src/AvatarGroup/AvatarGroupContext.ts
@@ -3,12 +3,13 @@
/**
* @file AvatarGroupContext.ts
- * @input None (pure context definition)
+ * @input Layer-scoped React context
* @output Exports AvatarGroup context and useAvatarGroup hook
* @position Shared context; consumed by children for group-aware styling
*/
-import {createContext, use} from 'react';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
import type {AvatarShape, AvatarSize} from '../Avatar';
export interface AvatarGroupContextValue {
diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.tsx
index 5715bfb3db..dfd7ddba37 100644
--- a/packages/core/src/BottomSheet/BottomSheetPanel.tsx
+++ b/packages/core/src/BottomSheet/BottomSheetPanel.tsx
@@ -4,7 +4,7 @@
/**
* @file BottomSheetPanel.tsx
- * @input Uses React, StyleX, theme tokens, sheet gestures, shared scroll behavior, and the host label
+ * @input Uses React, StyleX, theme tokens, text/provider boundaries, sheet gestures, shared scroll behavior, and the host label
* @output Internal BottomSheetPanel with a keyboard-reachable scrolling body and motion-state types
* @position Shared presentation layer for standalone and switcher BottomSheets
*
@@ -47,6 +47,8 @@ import {
} from '../theme/tokens.stylex';
import {mergeProps, themeProps} from '../utils';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
+import {layerTextReset} from '../Layer/layerTextReset.stylex';
+import {LayerContentBoundary} from '../Layer/layerScopedContext';
import {overlayPaddingReset} from '../Layout/padding.stylex';
import {
isValidSnapPoint,
@@ -656,6 +658,7 @@ export function BottomSheetPanel({
{...mergeProps(
themeProps('bottom-sheet'),
stylex.props(
+ layerTextReset.reset,
styles.sheet,
overlayPaddingReset.reset,
height === 'hug' ? styles.hugHeight : styles.budget,
@@ -698,7 +701,7 @@ export function BottomSheetPanel({
),
})}>
<div {...getContentProps<HTMLDivElement>(stylex.props(styles.content))}>
- {children}
+ <LayerContentBoundary>{children}</LayerContentBoundary>
</div>
</div>
</div>
diff --git a/packages/core/src/Breadcrumbs/Breadcrumbs.tsx b/packages/core/src/Breadcrumbs/Breadcrumbs.tsx
index d336640bc8..655cd4a22d 100644
--- a/packages/core/src/Breadcrumbs/Breadcrumbs.tsx
+++ b/packages/core/src/Breadcrumbs/Breadcrumbs.tsx
@@ -4,7 +4,7 @@
/**
* @file Breadcrumbs.tsx
- * @input Uses React, createContext, stylex, theme tokens
+ * @input Uses React, layer-scoped context, stylex, theme tokens
* @output Exports Breadcrumbs component, BreadcrumbsProps, BreadcrumbContext
* @position Core container component; consumed by index.ts
*
@@ -16,7 +16,8 @@
* - /packages/cli/assets/templates/blocks/components/Breadcrumbs/ (showcase blocks)
*/
-import {createContext, useMemo, type ReactNode} from 'react';
+import {useMemo, type ReactNode} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
import * as stylex from '@stylexjs/stylex';
import {spacingVars} from '../theme/tokens.stylex';
import {mergeProps} from '../utils';
diff --git a/packages/core/src/Button/Button.tsx b/packages/core/src/Button/Button.tsx
index edcdc2d914..357956b55c 100644
--- a/packages/core/src/Button/Button.tsx
+++ b/packages/core/src/Button/Button.tsx
@@ -434,7 +434,7 @@ const loadingStyles = stylex.create({
* The leading edge still uses `:first-child` — a member's button always precedes
* its own layer, so the first button is genuinely `:first-child`.
*/
-const IS_LAST_ITEM = ':not(:has(~ *:not([popover]):not(template)))';
+const IS_LAST_ITEM = ':not(:has(~ *:not([popover]):not(template):not(dialog)))';
const groupStyles = stylex.create({
horizontal: {
diff --git a/packages/core/src/ButtonGroup/ButtonGroupContext.ts b/packages/core/src/ButtonGroup/ButtonGroupContext.ts
index ac568fc3c8..be12798d6a 100644
--- a/packages/core/src/ButtonGroup/ButtonGroupContext.ts
+++ b/packages/core/src/ButtonGroup/ButtonGroupContext.ts
@@ -4,12 +4,13 @@
/**
* @file ButtonGroupContext.ts
- * @input None (pure context definition)
+ * @input Layer-scoped React context
* @output Exports ButtonGroup context and useButtonGroup hook
* @position Shared context; consumed by Button for group-aware styling
*/
-import {createContext, use} from 'react';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
export type ButtonGroupOrientation = 'horizontal' | 'vertical';
@@ -18,8 +19,9 @@ export interface ButtonGroupContextValue {
isDisabled: boolean;
}
-export const ButtonGroupContext =
- createContext<ButtonGroupContextValue | null>(null);
+export const ButtonGroupContext = createContext<ButtonGroupContextValue | null>(
+ null,
+);
ButtonGroupContext.displayName = 'ButtonGroupContext';
/**
diff --git a/packages/core/src/Chat/ChatContext.tsx b/packages/core/src/Chat/ChatContext.tsx
index 56e29f92a3..4ac52cedad 100644
--- a/packages/core/src/Chat/ChatContext.tsx
+++ b/packages/core/src/Chat/ChatContext.tsx
@@ -4,7 +4,7 @@
/**
* @file ChatContext.tsx
- * @input Uses React createContext
+ * @input Layer-scoped React context
* @output Exports Chat message/list/composer/layout contexts. The composer
* context (value + input-control registration) is public composition API,
* re-exported from Chat/index.ts for custom inputs.
@@ -13,6 +13,7 @@
*/
import {createContext, use, type RefObject} from 'react';
+import {createLayerScopedContext} from '../Layer/layerScopedContext';
export type ChatMessageSender = 'user' | 'assistant' | 'system';
export type ChatDensity = 'compact' | 'balanced' | 'spacious';
@@ -22,9 +23,8 @@ export interface ChatMessageContextValue {
density: ChatDensity;
}
-export const ChatMessageContext = createContext<ChatMessageContextValue | null>(
- null,
-);
+export const ChatMessageContext =
+ createLayerScopedContext<ChatMessageContextValue | null>(null);
ChatMessageContext.displayName = 'ChatMessageContext';
export function useChatMessageContext(): ChatMessageContextValue | null {
@@ -35,7 +35,8 @@ export interface ChatListContextValue {
density: ChatDensity;
}
-export const ChatListContext = createContext<ChatListContextValue | null>(null);
+export const ChatListContext =
+ createLayerScopedContext<ChatListContextValue | null>(null);
ChatListContext.displayName = 'ChatListContext';
export function useChatListContext(): ChatListContextValue | null {
diff --git a/packages/core/src/CheckboxList/CheckboxListContext.tsx b/packages/core/src/CheckboxList/CheckboxListContext.tsx
index 9112809cef..b7dd5783b5 100644
--- a/packages/core/src/CheckboxList/CheckboxListContext.tsx
+++ b/packages/core/src/CheckboxList/CheckboxListContext.tsx
@@ -4,12 +4,12 @@
/**
* @file CheckboxListContext.tsx
- * @input Uses React createContext
+ * @input Uses the private layer-scoped context factory
* @output Exports CheckboxListContext for parent-child communication
* @position Internal context; consumed by CheckboxList.tsx and CheckboxListItem.tsx
*/
-import {createContext} from 'react';
+import {createLayerScopedContext} from '../Layer/layerScopedContext';
export interface CheckboxListContextValue {
value?: string[];
@@ -37,5 +37,5 @@ export interface CheckboxListContextValue {
}
export const CheckboxListContext =
- createContext<CheckboxListContextValue | null>(null);
+ createLayerScopedContext<CheckboxListContextValue | null>(null);
CheckboxListContext.displayName = 'CheckboxListContext';
diff --git a/packages/core/src/Collapsible/CollapsibleGroupContext.tsx b/packages/core/src/Collapsible/CollapsibleGroupContext.tsx
index 8dbfa24f57..d3dacd6e86 100644
--- a/packages/core/src/Collapsible/CollapsibleGroupContext.tsx
+++ b/packages/core/src/Collapsible/CollapsibleGroupContext.tsx
@@ -4,7 +4,7 @@
/**
* @file CollapsibleGroupContext.tsx
- * @input Uses React createContext
+ * @input Layer-scoped React context
* @output Exports CollapsibleGroupContext, CollapsibleGroupContextValue,
* CollapsibleGroupPresentationContext, CollapsibleGroupPresentationValue,
* CollapsibleGroupDensity, and CollapsibleChevronPosition types
@@ -17,6 +17,7 @@
*/
import {createContext} from 'react';
+import {createLayerScopedContext} from '../Layer/layerScopedContext';
/**
* Context value provided by CollapsibleGroup to coordinate collapsible children.
@@ -78,6 +79,6 @@ export interface CollapsibleGroupPresentationValue {
* children so nested collapsibles never inherit row chrome.
*/
export const CollapsibleGroupPresentationContext =
- createContext<CollapsibleGroupPresentationValue | null>(null);
+ createLayerScopedContext<CollapsibleGroupPresentationValue | null>(null);
CollapsibleGroupPresentationContext.displayName =
'CollapsibleGroupPresentationContext';
diff --git a/packages/core/src/Dialog/Dialog.doc.mjs b/packages/core/src/Dialog/Dialog.doc.mjs
index 234eb90abe..4d9a5ebb5d 100644
--- a/packages/core/src/Dialog/Dialog.doc.mjs
+++ b/packages/core/src/Dialog/Dialog.doc.mjs
@@ -44,7 +44,8 @@ export const docs = {
{property: 'padding', expand: 'container'},
],
},
- description: 'Modal dialog using the native <dialog> element.',
+ description:
+ 'Modal dialog using the native <dialog> element. Modal and inline content starts with theme body text defaults. Ancestor surface/group membership ends as a whole, including group-owned state. Explicit props and unrelated contexts remain unchanged. Place intentional groups and complete required providers inside the dialog.',
props: [
{
name: 'isOpen',
@@ -157,7 +158,8 @@ export const docsZh = {
export const docsDense = {
description: 'modal overlay that blocks page interaction until the user responds',
usage: {
- description: 'Dialog displays a modal overlay that blocks page interaction. Use for delete confirmations, edit forms, terms acceptance.',
+ description:
+ 'Dialog displays a modal overlay that blocks page interaction. Use for delete confirmations, edit forms, terms acceptance. Modal and inline content uses theme body defaults and exits ancestor surface/group membership as a whole; explicit props and unrelated contexts remain unchanged. Provide intentional groups and complete required providers inside the dialog.',
bestPractices: [
{ guidance: true, description: 'Choose the right purpose: info for dismissable content, form to prevent accidental backdrop dismissal, required when user must respond.' },
{ guidance: true, description: 'Include a clear title in the header so users immediately understand what the dialog is asking.' },
diff --git a/packages/core/src/Dialog/Dialog.tsx b/packages/core/src/Dialog/Dialog.tsx
index 9f7ae585c7..624f7b91c9 100644
--- a/packages/core/src/Dialog/Dialog.tsx
+++ b/packages/core/src/Dialog/Dialog.tsx
@@ -4,7 +4,7 @@
/**
* @file Dialog.tsx
- * @input Uses React, DialogHTMLAttributes, ReactNode, container (Layout), DialogContext
+ * @input Uses React, DialogHTMLAttributes, ReactNode, container (Layout), DialogContext, layerTextReset
* @output Exports Dialog component, DialogProps, DialogVariant, DialogPurpose types
* @position Core implementation; consumed by index.ts, tested by Dialog.test.tsx
*
@@ -34,6 +34,8 @@ import {
import type {BaseProps} from '../BaseProps';
import * as stylex from '@stylexjs/stylex';
import {useScrollLock} from '../hooks/useScrollLock';
+import {layerTextReset} from '../Layer/layerTextReset.stylex';
+import {LayerContentBoundary} from '../Layer/layerScopedContext';
import {LayerDepthProvider} from '../Layer/LayerDepthContext';
import {useLayerDismissal} from '../Layer/useLayerDismissal';
import {
@@ -674,6 +676,7 @@ export function Dialog({
{...mergeProps(
themeProps('dialog', {variant}),
stylex.props(
+ layerTextReset.reset,
styles.inlineWrapper,
overlayPaddingReset.reset,
standardSizing &&
@@ -692,7 +695,9 @@ export function Dialog({
(props as Record<string, unknown>)['data-testid'] as
string | undefined
}>
- <LayerDepthProvider>{innerContent}</LayerDepthProvider>
+ <LayerDepthProvider>
+ <LayerContentBoundary>{innerContent}</LayerContentBoundary>
+ </LayerDepthProvider>
</div>
);
}
@@ -706,6 +711,7 @@ export function Dialog({
{...mergeProps(
themeProps('dialog', {variant}),
focusOutlineProps.focusVisible(
+ layerTextReset.reset,
styles.dialog,
overlayPaddingReset.reset,
isOpen && styles.open,
@@ -740,7 +746,9 @@ export function Dialog({
// imperatively in `attachDialog`; a consumer-provided aria-labelledby
// flows through {...safeProps} above and wins.
{...(purpose === 'required' ? {role: 'alertdialog'} : undefined)}>
- <LayerDepthProvider>{innerContent}</LayerDepthProvider>
+ <LayerDepthProvider>
+ <LayerContentBoundary>{innerContent}</LayerContentBoundary>
+ </LayerDepthProvider>
</dialog>
);
}
diff --git a/packages/core/src/DropdownMenu/DropdownMenuContext.tsx b/packages/core/src/DropdownMenu/DropdownMenuContext.tsx
index 5408259167..d08bfbeba9 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuContext.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenuContext.tsx
@@ -4,6 +4,7 @@
/**
* @file DropdownMenuContext.tsx
+ * @input Layer-scoped React context
* @output Exports context and hook for compound-component menu coordination
* @position Internal; used by DropdownMenu and DropdownMenuItem
*
@@ -13,6 +14,7 @@
*/
import {createContext, use} from 'react';
+import {createLayerScopedContext} from '../Layer/layerScopedContext';
/** Menu size, derived from the trigger button size. */
export type DropdownMenuSize = 'sm' | 'md' | 'lg';
@@ -25,7 +27,7 @@ export interface DropdownMenuContextValue {
}
export const DropdownMenuContext =
- createContext<DropdownMenuContextValue | null>(null);
+ createLayerScopedContext<DropdownMenuContextValue | null>(null);
DropdownMenuContext.displayName = 'DropdownMenuContext';
/**
diff --git a/packages/core/src/FormLayout/FormLayoutContext.ts b/packages/core/src/FormLayout/FormLayoutContext.ts
index 6827fdb381..b8151428c8 100644
--- a/packages/core/src/FormLayout/FormLayoutContext.ts
+++ b/packages/core/src/FormLayout/FormLayoutContext.ts
@@ -4,7 +4,7 @@
/**
* @file FormLayoutContext.ts
- * @input Uses React createContext
+ * @input Layer-scoped React context
* @output Exports FormLayoutContext, FormLayoutDirection, and FormOptionality types
* @position Context for form layout direction + default-optionality detection
*
@@ -14,7 +14,7 @@
* - /packages/core/src/FormLayout/index.ts (exports if types change)
*/
-import {createContext} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
/**
* Direction of form field arrangement.
diff --git a/packages/core/src/Icon/IconDefaultSizeContext.ts b/packages/core/src/Icon/IconDefaultSizeContext.ts
index 2415b3a417..0278b03068 100644
--- a/packages/core/src/Icon/IconDefaultSizeContext.ts
+++ b/packages/core/src/Icon/IconDefaultSizeContext.ts
@@ -4,12 +4,13 @@
/**
* @file IconDefaultSizeContext.ts
- * @input Uses React context and an optional Icon size prop
+ * @input Uses layer-scoped React context and an optional Icon size prop
* @output Supplies a component-owned default size to descendant Icon instances
* @position Internal Icon sizing context; consumed by Icon and icon-slot owners
*/
-import {createContext, use} from 'react';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
import type {IconSize} from './IconSize.stylex';
const IconDefaultSizeContext = createContext<IconSize | null>(null);
diff --git a/packages/core/src/InputGroup/InputGroupContext.ts b/packages/core/src/InputGroup/InputGroupContext.ts
index a7aff09028..f7f741d600 100644
--- a/packages/core/src/InputGroup/InputGroupContext.ts
+++ b/packages/core/src/InputGroup/InputGroupContext.ts
@@ -4,12 +4,13 @@
/**
* @file InputGroupContext.ts
- * @input React createContext/use
+ * @input Layer-scoped React context/use
* @output Exports InputGroup context and useInputGroup hook
* @position Shared context; consumed by input components for group-aware styling and ARIA associations
*/
-import {createContext, use} from 'react';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
export interface InputGroupContextValue {
isInGroup: true;
diff --git a/packages/core/src/InputGroup/groupStyles.ts b/packages/core/src/InputGroup/groupStyles.ts
index f3c341e867..c1f41b639e 100644
--- a/packages/core/src/InputGroup/groupStyles.ts
+++ b/packages/core/src/InputGroup/groupStyles.ts
@@ -2,7 +2,7 @@
/**
* @file groupStyles.ts
- * @input Uses StyleX, theme tokens
+ * @input Uses StyleX, theme tokens, and layer-aware group end-cap selectors
* @output Exports shared group-aware styles for input components
* @position Shared styles consumed by InputGroup-compatible controls
*/
@@ -11,9 +11,9 @@ import * as stylex from '@stylexjs/stylex';
import {radiusVars, borderVars} from '../theme/tokens.stylex';
// A grouped control may be followed by context-layer infrastructure rather
-// than another control. Neither the inert marker nor the popover is a visual
-// group member, so skip both when finding the trailing edge.
-const IS_LAST_ITEM = ':not(:has(~ *:not([popover]):not(template)))';
+// than another control. Popovers, inert markers, and native dialog surfaces
+// are not visual group members; skip them when finding the trailing edge.
+const IS_LAST_ITEM = ':not(:has(~ *:not([popover]):not(template):not(dialog)))';
export const groupStyles = stylex.create({
inGroup: {
diff --git a/packages/core/src/Layer/Layer.doc.mjs b/packages/core/src/Layer/Layer.doc.mjs
index 42c12d9980..6a43fd8594 100644
--- a/packages/core/src/Layer/Layer.doc.mjs
+++ b/packages/core/src/Layer/Layer.doc.mjs
@@ -20,7 +20,7 @@ export const docs = {
],
usage: {
description:
- 'Layer utilities provide the app-level provider used by overlay systems. Use LayerProvider at the app root for toast/layer configuration; use higher-level Popover, HoverCard, or Tooltip APIs for most overlay UI.',
+ 'Layer utilities provide the app-level provider used by overlay systems. Use LayerProvider at the app root for toast/layer configuration; use higher-level Popover, HoverCard, or Tooltip APIs for most overlay UI. Rendered layer content, not the provider’s application subtree, uses theme body text defaults and exits ancestor surface/group membership. Establish intentional groups and complete required providers inside each layer.',
bestPractices: [
{
guidance: true,
@@ -67,7 +67,7 @@ export const docs = {
export const docsDense = {
usage: {
description:
- 'App-level provider for overlay systems. Use LayerProvider at app root for toast/layer config; use Popover/HoverCard/Tooltip for most overlay UI.',
+ 'App-level provider for overlay systems. Use LayerProvider at app root for toast/layer config; use Popover/HoverCard/Tooltip for most overlay UI. Layer content uses theme body defaults and exits ancestor surface/group membership; establish intentional groups and complete required providers inside it. The application subtree is unchanged.',
bestPractices: [
{
guidance: true,
diff --git a/packages/core/src/Layer/LayerDepthContext.tsx b/packages/core/src/Layer/LayerDepthContext.tsx
index f606d92fda..24f8491f49 100644
--- a/packages/core/src/Layer/LayerDepthContext.tsx
+++ b/packages/core/src/Layer/LayerDepthContext.tsx
@@ -4,7 +4,7 @@
/**
* @file LayerDepthContext.tsx
- * @input React context
+ * @input React depth context
* @output Exports LayerDepthContext, useLayerDepth, LayerDepthProvider
* @position Layer system; how the dismissal stack learns which layer is nested
* inside which.
diff --git a/packages/core/src/Layer/layerScopedContext.test.tsx b/packages/core/src/Layer/layerScopedContext.test.tsx
new file mode 100644
index 0000000000..9f96f3f0ef
--- /dev/null
+++ b/packages/core/src/Layer/layerScopedContext.test.tsx
@@ -0,0 +1,499 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file layerScopedContext.test.tsx
+ * @input Scoped context boundaries and grouped controls
+ * @output Whole membership, local ownership, and state preservation regressions
+ * @position Behavior coverage for AST-038 provider boundaries
+ */
+
+import {createContext, use, useState, type ReactNode} from 'react';
+import {afterEach, describe, expect, it, vi} from 'vitest';
+import {cleanup, fireEvent, render, screen} from '@testing-library/react';
+import {
+ createLayerScopedContext,
+ LayerContentBoundary,
+} from './layerScopedContext';
+import {Dialog} from '../Dialog';
+import {useLayer} from './useLayer';
+import {Button} from '../Button';
+import {ButtonGroup} from '../ButtonGroup';
+import {InputGroup} from '../InputGroup';
+import {TextInput} from '../TextInput';
+import {Avatar} from '../Avatar';
+import {AvatarGroup} from '../AvatarGroup';
+import {
+ IconDefaultSizeProvider,
+ useIconSize,
+} from '../Icon/IconDefaultSizeContext';
+import {ToggleButton, ToggleButtonGroup} from '../ToggleButton';
+import {FormLayoutContext} from '../FormLayout';
+import {LayoutAreaContext} from '../Layout/LayoutAreaContext';
+import {TabListContext, useTabListContext} from '../TabList/TabListContext';
+import {
+ SegmentedControlContext,
+ useSegmentedControlContext,
+} from '../SegmentedControl/SegmentedControlContext';
+import {
+ RadioListContext,
+ type RadioListContextValue,
+} from '../RadioList/RadioList';
+import {RadioListItem} from '../RadioList';
+import {CheckboxListContext} from '../CheckboxList/CheckboxListContext';
+import {
+ DropdownMenuContext,
+ DropdownMenuRadioGroupContext,
+} from '../DropdownMenu/DropdownMenuContext';
+import {LayerDepthContext, LayerDepthProvider} from './LayerDepthContext';
+import {Stepper, Step} from '../Stepper';
+import {
+ StepperContext,
+ StepperInternalContext,
+} from '../Stepper/StepperContext';
+
+const noop = () => {};
+const Scoped = createLayerScopedContext('default');
+const ServiceContext = createContext('service');
+ServiceContext.displayName = 'ServiceContext';
+
+function ReadScope({id}: {id: string}) {
+ return (
+ <output data-testid={id}>
+ {use(Scoped)}:{use(ServiceContext)}
+ </output>
+ );
+}
+function Fixed({children}: {children: ReactNode}) {
+ const layer = useLayer({mode: 'fixed'});
+ // jsdom does not paint :popover-open; this exercises context, not visibility.
+ return <>{layer.render(children, {x: 0, y: 0, style: {display: 'block'}})}</>;
+}
+const boundaries = [
+ ['fixed Layer', (content: ReactNode) => <Fixed>{content}</Fixed>],
+ [
+ 'inline Dialog',
+ (content: ReactNode) => (
+ <Dialog isOpen isInline onOpenChange={noop}>
+ {content}
+ </Dialog>
+ ),
+ ],
+] as const;
+
+afterEach(cleanup);
+
+describe('layer-scoped context', () => {
+ it('uses the complete default value rather than retaining ancestor fields', () => {
+ const fallback = {
+ isDisabled: false,
+ selected: new Set<string>(),
+ onChange: vi.fn(),
+ };
+ const Membership = createLayerScopedContext(fallback);
+ const outer = {
+ isDisabled: true,
+ selected: new Set(['outer']),
+ onChange: vi.fn(),
+ };
+ function Probe() {
+ expect(use(Membership)).toBe(fallback);
+ return null;
+ }
+ const tree = (value: typeof outer) => (
+ <Membership value={value}>
+ <LayerContentBoundary>
+ <Probe />
+ </LayerContentBoundary>
+ </Membership>
+ );
+ const {rerender} = render(tree(outer));
+ rerender(tree({...outer, selected: new Set(['updated'])}));
+ });
+
+ it('keeps the public depth provider limited to depth', () => {
+ const Membership = createLayerScopedContext('default');
+ function Probe() {
+ expect(use(Membership)).toBe('outer');
+ expect(use(LayerDepthContext)).toBe(3);
+ return null;
+ }
+ render(
+ <Membership value="outer">
+ <LayerDepthContext value={2}>
+ <LayerDepthProvider>
+ <Probe />
+ </LayerDepthProvider>
+ </LayerDepthContext>
+ </Membership>,
+ );
+ });
+
+ it('isolates future scoped providers, not unrelated application services', () => {
+ render(
+ <ServiceContext value="live service">
+ <Scoped value="outer">
+ <ReadScope id="outside" />
+ <LayerContentBoundary>
+ <ReadScope id="isolated" />
+ <Scoped value="content">
+ <ReadScope id="local" />
+ <LayerContentBoundary>
+ <ReadScope id="nested" />
+ </LayerContentBoundary>
+ </Scoped>
+ </LayerContentBoundary>
+ </Scoped>
+ </ServiceContext>,
+ );
+ expect(screen.getByTestId('outside')).toHaveTextContent(
+ 'outer:live service',
+ );
+ expect(screen.getByTestId('isolated')).toHaveTextContent(
+ 'default:live service',
+ );
+ expect(screen.getByTestId('local')).toHaveTextContent(
+ 'content:live service',
+ );
+ expect(screen.getByTestId('nested')).toHaveTextContent(
+ 'default:live service',
+ );
+ });
+
+ it('preserves content state and focus when another module registers a context', () => {
+ function Content() {
+ const [value, setValue] = useState('');
+ return (
+ <input
+ aria-label="Draft"
+ value={value}
+ onChange={e => setValue(e.target.value)}
+ />
+ );
+ }
+ const {rerender} = render(
+ <LayerContentBoundary>
+ <Content />
+ </LayerContentBoundary>,
+ );
+ const input = screen.getByRole('textbox');
+ fireEvent.change(input, {target: {value: 'keep me'}});
+ input.focus();
+ const Late = createLayerScopedContext('late default');
+ rerender(
+ <LayerContentBoundary>
+ <Content />
+ </LayerContentBoundary>,
+ );
+ expect(screen.getByRole('textbox')).toBe(input);
+ expect(input).toHaveValue('keep me');
+ expect(input).toHaveFocus();
+ function ReadLate() {
+ return <output>{use(Late)}</output>;
+ }
+ render(
+ <Late value="outer late">
+ <LayerContentBoundary>
+ <ReadLate />
+ </LayerContentBoundary>
+ </Late>,
+ );
+ expect(screen.getByText('late default')).toBeInTheDocument();
+ });
+
+ it('keeps explicit content-provider updates live', () => {
+ const content = (value: string) => (
+ <LayerContentBoundary>
+ <Scoped value={value}>
+ <ReadScope id="content" />
+ </Scoped>
+ </LayerContentBoundary>
+ );
+ const {rerender} = render(content('first'));
+ rerender(content('second'));
+ expect(screen.getByTestId('content')).toHaveTextContent('second:service');
+ });
+});
+
+describe.each(boundaries)('%s provider boundary', (name, boundary) => {
+ it('preserves unrelated collection protocols and semantic layout ownership', () => {
+ const callback = vi.fn();
+ const radio = {value: 'one', onChange: callback, hasCloseOnSelect: false};
+ function Probe() {
+ expect(use(DropdownMenuRadioGroupContext)).toBe(radio);
+ expect(use(LayoutAreaContext)).toBe('header');
+ return null;
+ }
+ render(
+ <DropdownMenuRadioGroupContext value={radio}>
+ <LayoutAreaContext value="header">
+ {boundary(<Probe />)}
+ </LayoutAreaContext>
+ </DropdownMenuRadioGroupContext>,
+ );
+ });
+
+ it('ends CheckboxList membership and preserves a complete local owner', () => {
+ const outer = {
+ value: ['outer'],
+ onChange: vi.fn(),
+ isDisabled: true,
+ isReadOnly: true,
+ };
+ const local = {
+ value: ['local'],
+ onChange: vi.fn(),
+ isDisabled: false,
+ isReadOnly: false,
+ };
+ function Probe({expected}: {expected: typeof outer | null}) {
+ expect(use(CheckboxListContext)).toBe(expected);
+ return null;
+ }
+ render(
+ <CheckboxListContext value={outer}>
+ {boundary(
+ <>
+ <Probe expected={null} />
+ <CheckboxListContext value={local}>
+ <Probe expected={local} />
+ </CheckboxListContext>
+ </>,
+ )}
+ </CheckboxListContext>,
+ );
+ });
+
+ it('ends ancestor membership and preserves complete content-local providers', () => {
+ const outerChange = vi.fn();
+ const localChange = vi.fn();
+ const tabs = {
+ value: 'outer',
+ onChange: outerChange,
+ size: 'lg',
+ layout: 'fill',
+ pattern: 'tabs',
+ } as const;
+ const segments = {
+ value: 'outer',
+ onChange: outerChange,
+ size: 'lg',
+ layout: 'fill',
+ isDisabled: true,
+ } as const;
+ const radios: RadioListContextValue = {
+ name: 'outer',
+ value: 'outer',
+ onChange: outerChange,
+ isDisabled: true,
+ hasDisabledMessage: false,
+ isRequired: false,
+ size: 'md',
+ };
+ const menu = {closeMenu: outerChange, menuSize: 'lg'} as const;
+ const localTabs = {...tabs, value: 'inner', onChange: localChange};
+ const localSegments = {
+ ...segments,
+ value: 'inner',
+ onChange: localChange,
+ isDisabled: false,
+ };
+ const localRadios = {
+ ...radios,
+ name: 'inner',
+ value: 'inner',
+ onChange: localChange,
+ isDisabled: false,
+ };
+ const localMenu = {...menu, closeMenu: localChange};
+ function OutsideLocalProvider() {
+ expect(use(TabListContext)).toBeNull();
+ expect(use(SegmentedControlContext)).toBeNull();
+ expect(use(RadioListContext)).toBeNull();
+ expect(use(DropdownMenuContext)).toBeNull();
+ expect(use(FormLayoutContext).defaultOptionality).toBeUndefined();
+ return null;
+ }
+ function InsideLocalProvider() {
+ expect(useTabListContext()).toBe(localTabs);
+ expect(useSegmentedControlContext()).toBe(localSegments);
+ expect(use(RadioListContext)).toBe(localRadios);
+ expect(use(DropdownMenuContext)).toBe(localMenu);
+ return <RadioListItem label="Local option" value="inner" />;
+ }
+ render(
+ <TabListContext value={tabs}>
+ <SegmentedControlContext value={segments}>
+ <RadioListContext value={radios}>
+ <DropdownMenuContext value={menu}>
+ <FormLayoutContext
+ value={{
+ direction: 'horizontal-labels',
+ defaultOptionality: 'required',
+ }}>
+ {boundary(
+ <>
+ <OutsideLocalProvider />
+ <TabListContext value={localTabs}>
+ <SegmentedControlContext value={localSegments}>
+ <RadioListContext value={localRadios}>
+ <DropdownMenuContext value={localMenu}>
+ <InsideLocalProvider />
+ </DropdownMenuContext>
+ </RadioListContext>
+ </SegmentedControlContext>
+ </TabListContext>
+ </>,
+ )}
+ </FormLayoutContext>
+ </DropdownMenuContext>
+ </RadioListContext>
+ </SegmentedControlContext>
+ </TabListContext>,
+ );
+ expect(screen.getByRole('radio', {name: 'Local option'})).toBeChecked();
+ expect(screen.getByRole('radio', {name: 'Local option'})).toBeEnabled();
+ expect(outerChange).not.toHaveBeenCalled();
+ });
+
+ it('uses standalone icon sizing while retaining outer and explicit inner owners', () => {
+ function IconSize({id}: {id: string}) {
+ return <output data-testid={id}>{useIconSize(undefined)}</output>;
+ }
+ render(
+ <>
+ <IconSize id="standalone-size" />
+ <IconDefaultSizeProvider value="sm">
+ <IconSize id="outer-size" />
+ {boundary(
+ <>
+ <IconSize id="layer-size" />
+ <IconDefaultSizeProvider value="lg">
+ <IconSize id="local-size" />
+ </IconDefaultSizeProvider>
+ </>,
+ )}
+ </IconDefaultSizeProvider>
+ </>,
+ );
+ expect(screen.getByTestId('standalone-size')).toHaveTextContent('md');
+ expect(screen.getByTestId('outer-size')).toHaveTextContent('sm');
+ expect(screen.getByTestId('layer-size').textContent).toBe(
+ screen.getByTestId('standalone-size').textContent,
+ );
+ expect(screen.getByTestId('local-size')).toHaveTextContent('lg');
+ });
+
+ it('ends stepper membership while a complete inner stepper owns its actions', () => {
+ const outerChange = vi.fn();
+ const localChange = vi.fn();
+ function Independent() {
+ expect(use(StepperContext)).toBeNull();
+ expect(use(StepperInternalContext)).toBeNull();
+ return (
+ <Stepper activeStep={0} onStepClick={localChange}>
+ <Step step={0} label="Local first" />
+ <Step step={1} label="Local second" />
+ </Stepper>
+ );
+ }
+ render(
+ <Stepper activeStep={1} onStepClick={outerChange}>
+ <Step step={0} label="Outer first" />
+ <Step step={1} label="Outer second" />
+ {boundary(<Independent />)}
+ </Stepper>,
+ );
+ fireEvent.click(screen.getByRole('button', {name: /Local second/}));
+ expect(localChange).toHaveBeenCalledWith(1);
+ expect(outerChange).not.toHaveBeenCalled();
+ });
+
+ it('keeps existing layer-depth semantics', () => {
+ function Depth() {
+ return <output>{use(LayerDepthContext)}</output>;
+ }
+ render(
+ <LayerDepthContext value={4}>{boundary(<Depth />)}</LayerDepthContext>,
+ );
+ expect(
+ screen.getByText(name === 'fixed Layer' ? '4' : '5'),
+ ).toBeInTheDocument();
+ });
+
+ it('ends group-owned disabled state while preserving explicit and inner-group state', () => {
+ const press = vi.fn();
+ render(
+ <ButtonGroup label="Outer" isDisabled>
+ <Button label="Outer member" />
+ {boundary(
+ <>
+ <Button label="Independent" onClick={press} />
+ <Button label="Explicit disabled" isDisabled />
+ <ButtonGroup label="Inner" isDisabled>
+ <Button label="Inner member" />
+ </ButtonGroup>
+ </>,
+ )}
+ </ButtonGroup>,
+ );
+ expect(screen.getByRole('button', {name: 'Outer member'})).toBeDisabled();
+ const independent = screen.getByRole('button', {name: 'Independent'});
+ expect(independent).toBeEnabled();
+ fireEvent.click(independent);
+ expect(press).toHaveBeenCalledOnce();
+ expect(
+ screen.getByRole('button', {name: 'Explicit disabled'}),
+ ).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Inner member'})).toBeDisabled();
+ });
+
+ it('ends group-owned labels without changing the content input label', () => {
+ render(
+ <InputGroup label="Outer label">
+ {boundary(<TextInput label="Inner label" value="" onChange={noop} />)}
+ </InputGroup>,
+ );
+ expect(
+ screen.getByRole('textbox', {name: 'Inner label'}),
+ ).toHaveAccessibleName('Inner label');
+ });
+
+ it('ends ancestor selection and callbacks while honoring explicit toggle props', () => {
+ const outerChange = vi.fn();
+ const localChange = vi.fn();
+ render(
+ <ToggleButtonGroup label="Outer" value="x" onChange={outerChange}>
+ {boundary(
+ <ToggleButton
+ value="x"
+ label="Independent"
+ isPressed={false}
+ onPressedChange={localChange}
+ />,
+ )}
+ </ToggleButtonGroup>,
+ );
+ const toggle = screen.getByRole('button', {name: 'Independent'});
+ expect(toggle).toHaveAttribute('aria-pressed', 'false');
+ fireEvent.click(toggle);
+ expect(localChange).toHaveBeenCalledWith(true, expect.anything());
+ expect(outerChange).not.toHaveBeenCalled();
+ });
+
+ it('restores standalone tooltip focusability while preserving an inner avatar group', () => {
+ render(
+ <AvatarGroup>
+ {boundary(
+ <>
+ <Avatar name="Independent" data-testid="avatar" />
+ <AvatarGroup>
+ <Avatar name="Inner" data-testid="inner-avatar" />
+ </AvatarGroup>
+ </>,
+ )}
+ </AvatarGroup>,
+ );
+ expect(screen.getByTestId('avatar')).toHaveAttribute('tabindex', '0');
+ expect(screen.getByTestId('inner-avatar')).not.toHaveAttribute('tabindex');
+ });
+});
diff --git a/packages/core/src/Layer/layerScopedContext.tsx b/packages/core/src/Layer/layerScopedContext.tsx
new file mode 100644
index 0000000000..0b1f6c616f
--- /dev/null
+++ b/packages/core/src/Layer/layerScopedContext.tsx
@@ -0,0 +1,37 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @file layerScopedContext.tsx
+ * @input Surface-scoped React contexts and layer content
+ * @output Private context creation and whole-value content boundary
+ * @position AST-038 surface membership; unrelated contexts retain their owners
+ */
+
+import {createContext, useState, type Context, type ReactNode} from 'react';
+
+type Reset = (children: ReactNode) => ReactNode;
+const resets: Reset[] = [];
+
+/** Create a surface-scoped context whose whole default applies in a new layer. */
+export function createLayerScopedContext<T>(defaultValue: T): Context<T> {
+ const Context = createContext(defaultValue);
+ Context.displayName = 'LayerScopedContext';
+ resets.push(children => <Context value={defaultValue}>{children}</Context>);
+ return Context;
+}
+
+export function LayerContentBoundary({
+ children,
+}: {
+ children: ReactNode;
+}): ReactNode {
+ // Keep the provider chain stable for this mount: lazy imports must not
+ // remount existing content and discard its state or focus.
+ const [resetChain] = useState(() => resets.slice());
+ return resetChain.reduceRight(
+ (content, reset): ReactNode => reset(content),
+ children,
+ );
+}
diff --git a/packages/core/src/Layer/layerTextReset.stylex.ts b/packages/core/src/Layer/layerTextReset.stylex.ts
new file mode 100644
index 0000000000..f104f32809
--- /dev/null
+++ b/packages/core/src/Layer/layerTextReset.stylex.ts
@@ -0,0 +1,37 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file layerTextReset.stylex.ts
+ * @input Uses StyleX and the active theme's body typography tokens
+ * @output Shared text baseline for content-bearing layer roots
+ * @position Private Core styling; AST-038 owns the accepted contract
+ */
+
+import * as stylex from '@stylexjs/stylex';
+import {typeScaleVars, typographyVars} from '../theme/tokens.stylex';
+
+/**
+ * Apply before component and consumer styles on the layer's content boundary.
+ * Top-layer promotion does not stop DOM inheritance. Reset text formatting, not
+ * writing context, theme variables, surface colors, geometry, or interaction.
+ */
+export const layerTextReset = stylex.create({
+ reset: {
+ fontFamily: typographyVars['--font-family-body'],
+ fontSize: typeScaleVars['--text-body-size'],
+ fontWeight: typeScaleVars['--text-body-weight'],
+ lineHeight: typeScaleVars['--text-body-leading'],
+ fontStyle: 'normal',
+ textAlign: 'start',
+ textAlignLast: 'auto',
+ textIndent: 0,
+ textTransform: 'none',
+ letterSpacing: 'normal',
+ wordSpacing: 'normal',
+ textShadow: 'none',
+ whiteSpace: 'normal',
+ wordBreak: 'normal',
+ overflowWrap: 'normal',
+ hyphens: 'manual',
+ },
+});
diff --git a/packages/core/src/Layer/useLayer.doc.mjs b/packages/core/src/Layer/useLayer.doc.mjs
index 5c2e9c6704..7152ae1580 100644
--- a/packages/core/src/Layer/useLayer.doc.mjs
+++ b/packages/core/src/Layer/useLayer.doc.mjs
@@ -91,7 +91,7 @@ export const docs = {
],
usage: {
description:
- 'Core positioning hook for rendering overlay content using CSS Anchor Positioning and the Popover API. Use it as the foundation for custom popovers, hover cards, tooltips, and fixed-position layers when higher-level components are not enough.',
+ 'Core positioning hook for rendering overlay content using CSS Anchor Positioning and the Popover API. Use it as the foundation for custom popovers, hover cards, tooltips, and fixed-position layers when higher-level components are not enough. Both modes use theme body text defaults and end ancestor surface/group membership as a whole, including group-owned state. Explicit props and unrelated contexts remain unchanged. Apply intentional formatting through render styles or content, and establish complete content-local providers inside the rendered layer.',
bestPractices: [
{
guidance: true,
@@ -124,7 +124,7 @@ export const docs = {
/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */
export const docsDense = {
description:
- 'Core positioning hook for overlay content via CSS Anchor Positioning + Popover API. Foundation for custom popovers, hover cards, tooltips, fixed-position layers.',
+ 'Core positioning hook for overlay content via CSS Anchor Positioning + Popover API. Foundation for custom popovers, hover cards, tooltips, fixed-position layers. Both modes use theme body defaults and end ancestor surface/group membership as a whole. Explicit props and unrelated contexts remain unchanged; establish intentional groups and complete required providers inside the rendered layer.',
paramDescriptions: {
mode: 'positioning strategy: context = CSS anchor relative to trigger; fixed = explicit x/y coords',
onShow: 'fires when layer becomes visible.',
@@ -145,7 +145,7 @@ export const docsDense = {
},
usage: {
description:
- 'Core positioning hook for overlay content via CSS Anchor Positioning + Popover API. Foundation for custom popovers, hover cards, tooltips, fixed-position layers.',
+ 'Core positioning hook for overlay content via CSS Anchor Positioning + Popover API. Foundation for custom popovers, hover cards, tooltips, fixed-position layers. Both modes use theme body defaults and end ancestor surface/group membership as a whole. Explicit props and unrelated contexts remain unchanged; establish intentional groups and complete required providers inside the rendered layer.',
bestPractices: [
{
guidance: true,
diff --git a/packages/core/src/Layer/useLayer.tsx b/packages/core/src/Layer/useLayer.tsx
index 260638742f..30de135be6 100644
--- a/packages/core/src/Layer/useLayer.tsx
+++ b/packages/core/src/Layer/useLayer.tsx
@@ -4,7 +4,7 @@
/**
* @file useLayer.tsx
- * @input Uses React hooks, Popover API, CSS anchor positioning, typography tokens
+ * @input Uses React hooks, Popover API, CSS anchor positioning, shared text/provider boundaries
* @output Exports the public useLayer hook plus internal trigger helpers.
* @position Core layer utility; used by useHoverCard, useTooltip, etc.
*
@@ -27,10 +27,11 @@ import React, {
import * as stylex from '@stylexjs/stylex';
import type {StyleXStyles} from '@stylexjs/stylex';
import {createPortal} from 'react-dom';
+import {LayerContentBoundary} from './layerScopedContext';
import {addAnchorName, removeAnchorName} from './anchorName';
import {currentGesture, currentGestureHasClicked} from './gestureCounter';
import {resolveLayerPortalTarget} from './layerHost';
-import {typeScaleVars, typographyVars} from '../theme/tokens.stylex';
+import {layerTextReset} from './layerTextReset.stylex';
import {overlayPaddingReset} from '../Layout/padding.stylex';
const styles = stylex.create({
@@ -47,12 +48,6 @@ const styles = stylex.create({
borderWidth: 0,
borderStyle: 'none',
overflow: 'visible',
- // A layer is hosted wherever its trigger happens to sit, so type that is
- // inherited rather than declared makes the same component render at a
- // different size in different callers.
- fontFamily: typographyVars['--font-family-body'],
- fontSize: typeScaleVars['--text-body-size'],
- lineHeight: typeScaleVars['--text-body-leading'],
// Override browser default [popover] background (canvas color)
backgroundColor: 'transparent',
},
@@ -905,6 +900,7 @@ function useLayerImplementation(
: null;
const stylexResult = stylex.props(
+ layerTextReset.reset,
styles.base,
overlayPaddingReset.reset,
offsetStyle,
@@ -933,7 +929,7 @@ function useLayerImplementation(
}}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}>
- {children}
+ <LayerContentBoundary>{children}</LayerContentBoundary>
</Container>
);
@@ -974,6 +970,7 @@ function useLayerImplementation(
};
const stylexResult = stylex.props(
+ layerTextReset.reset,
styles.base,
overlayPaddingReset.reset,
styles.fixed,
@@ -990,7 +987,7 @@ function useLayerImplementation(
popover={lightDismiss ? 'auto' : 'manual'}
className={combinedClassName}
style={{...stylexResult.style, ...positionStyle, ...extraStyle}}>
- {children}
+ <LayerContentBoundary>{children}</LayerContentBoundary>
</div>
);
},
diff --git a/packages/core/src/Layout/LayoutDividerContext.ts b/packages/core/src/Layout/LayoutDividerContext.ts
index b37cf8428b..bd24f16082 100644
--- a/packages/core/src/Layout/LayoutDividerContext.ts
+++ b/packages/core/src/Layout/LayoutDividerContext.ts
@@ -4,7 +4,7 @@
/**
* @file LayoutDividerContext.ts
- * @input Uses React createContext
+ * @input Layer-scoped React context
* @output Exports LayoutDividerContext and LayoutDividerContextValue type
* @position Context for container-controlled default divider visibility;
* consumed by LayoutHeader.tsx, LayoutFooter.tsx, provided by Layout.tsx
@@ -16,7 +16,7 @@
* - /packages/core/src/Layout/LayoutFooter.tsx
*/
-import {createContext} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
export interface LayoutDividerContextValue {
defaultHasDividers: boolean;
diff --git a/packages/core/src/Layout/LayoutSlotsContext.ts b/packages/core/src/Layout/LayoutSlotsContext.ts
index d500efdcf6..d728fd8f04 100644
--- a/packages/core/src/Layout/LayoutSlotsContext.ts
+++ b/packages/core/src/Layout/LayoutSlotsContext.ts
@@ -4,7 +4,7 @@
/**
* @file LayoutSlotsContext.ts
- * @input Uses React createContext
+ * @input Layer-scoped React context
* @output Exports LayoutSlotsContext and LayoutSlots type
* @position Context for layout slot information
*
@@ -13,7 +13,7 @@
* - /packages/core/src/Layout/Layout/index.ts
*/
-import {createContext} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
/**
* Information about which layout slots are filled.
diff --git a/packages/core/src/Lightbox/Lightbox.tsx b/packages/core/src/Lightbox/Lightbox.tsx
index 526b11f5d1..3de78ff899 100644
--- a/packages/core/src/Lightbox/Lightbox.tsx
+++ b/packages/core/src/Lightbox/Lightbox.tsx
@@ -4,7 +4,7 @@
/**
* @file Lightbox.tsx
- * @input Uses React, native dialog, StyleX, IconButton, theme tokens
+ * @input Uses React, native dialog, StyleX, IconButton, theme tokens, layerTextReset
* @output Exports Lightbox component, LightboxProps, LightboxMedia
* @position Core implementation; consumed by index.ts
*
@@ -37,6 +37,8 @@ import {mergeProps, rtlStyles} from '../utils';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
+import {layerTextReset} from '../Layer/layerTextReset.stylex';
+import {LayerContentBoundary} from '../Layer/layerScopedContext';
import {overlayPaddingReset} from '../Layout/padding.stylex';
import {LayerDepthProvider} from '../Layer/LayerDepthContext';
import {useLayerDismissal} from '../Layer/useLayerDismissal';
@@ -616,118 +618,140 @@ export function Lightbox({
aria-label={currentItem.alt || t('@astryx.lightbox.mediaViewer')}
{...mergeProps(
themeProps('lightbox'),
- stylex.props(styles.dialog, overlayPaddingReset.reset, xstyle),
+ stylex.props(
+ layerTextReset.reset,
+ styles.dialog,
+ overlayPaddingReset.reset,
+ xstyle,
+ ),
className,
style,
)}
{...props}>
<LayerDepthProvider>
- <div ref={containerRef} {...stylex.props(styles.container)}>
- {/* Close button */}
- <IconButton
- icon={<Icon icon="close" size="sm" color="inherit" />}
- label={t('@astryx.lightbox.close')}
- variant="ghost"
- onClick={handleClose}
- xstyle={[styles.closeButton, styles.controlButton]}
- />
-
- {/* Gallery nav: prev — stays mounted and is disabled at the start of
- the range so pressing/arrowing to the boundary doesn't unmount the
- focused control and drop focus to <body>. */}
- {isGallery && (
+ <LayerContentBoundary>
+ <div ref={containerRef} {...stylex.props(styles.container)}>
+ {/* Close button */}
<IconButton
- icon={
- <Icon
- icon="chevronLeft"
- size="sm"
- color="inherit"
- xstyle={rtlStyles.mirror}
- />
- }
- label={t('@astryx.lightbox.previous')}
+ icon={<Icon icon="close" size="sm" color="inherit" />}
+ label={t('@astryx.lightbox.close')}
variant="ghost"
- isDisabled={!canPrev}
- onClick={goToPrev}
- xstyle={[styles.navButton, styles.navPrev, styles.controlButton]}
+ onClick={handleClose}
+ xstyle={[styles.closeButton, styles.controlButton]}
/>
- )}
-
- {/* Media + caption group (centered together) */}
- <div {...stylex.props(styles.mediaGroup)}>
- <div
- ref={imageWrapperRef}
- // The wrapper is a keyboard-operable zoom toggle when zoom is
- // enabled: Enter/Space toggles, aria-pressed reflects state.
- role={isZoomTarget ? 'button' : undefined}
- tabIndex={isZoomTarget ? 0 : undefined}
- aria-pressed={isZoomTarget ? isZoomed : undefined}
- aria-label={isZoomTarget ? t('@astryx.lightbox.zoom') : undefined}
- {...stylex.props(
- styles.imageWrapper,
- isZoomTarget && focusOutlineStyles.focusVisible,
- !isVideo && hasZoom && !isZoomed && styles.imageWrapperZoomable,
- !isVideo && isZoomed && styles.imageWrapperZoomed,
- !isVideo && isDragging && styles.imageWrapperDragging,
- )}
- onDoubleClick={isVideo ? undefined : handleDoubleClick}
- onKeyDown={isZoomTarget ? handleImageKeyDown : undefined}
- onPointerDown={isVideo ? undefined : handlePointerDown}>
- {isVideo ? (
- <video
- src={currentItem.src}
- aria-label={currentItem.alt}
- controls
- autoPlay={hasAutoPlay}
- {...stylex.props(styles.video)}
- />
- ) : (
- <img
- src={currentItem.src}
- alt={currentItem.alt}
- draggable={false}
- {...stylex.props(
- styles.image,
- isDragging && styles.imageDragging,
- imageTransform != null &&
- dynamicStyles.imageTransform(imageTransform),
- )}
- />
- )}
- </div>
- {currentItem.caption && (
- <div {...stylex.props(styles.caption)}>{currentItem.caption}</div>
+ {/* Gallery nav: prev — stays mounted and is disabled at the start of
+ the range so pressing/arrowing to the boundary doesn't unmount the
+ focused control and drop focus to <body>. */}
+ {isGallery && (
+ <IconButton
+ icon={
+ <Icon
+ icon="chevronLeft"
+ size="sm"
+ color="inherit"
+ xstyle={rtlStyles.mirror}
+ />
+ }
+ label={t('@astryx.lightbox.previous')}
+ variant="ghost"
+ isDisabled={!canPrev}
+ onClick={goToPrev}
+ xstyle={[
+ styles.navButton,
+ styles.navPrev,
+ styles.controlButton,
+ ]}
+ />
)}
- </div>
- {/* Gallery nav: next — see "prev" above; stays mounted and disabled at
+ {/* Media + caption group (centered together) */}
+ <div {...stylex.props(styles.mediaGroup)}>
+ <div
+ ref={imageWrapperRef}
+ // The wrapper is a keyboard-operable zoom toggle when zoom is
+ // enabled: Enter/Space toggles, aria-pressed reflects state.
+ role={isZoomTarget ? 'button' : undefined}
+ tabIndex={isZoomTarget ? 0 : undefined}
+ aria-pressed={isZoomTarget ? isZoomed : undefined}
+ aria-label={
+ isZoomTarget ? t('@astryx.lightbox.zoom') : undefined
+ }
+ {...stylex.props(
+ styles.imageWrapper,
+ isZoomTarget && focusOutlineStyles.focusVisible,
+ !isVideo &&
+ hasZoom &&
+ !isZoomed &&
+ styles.imageWrapperZoomable,
+ !isVideo && isZoomed && styles.imageWrapperZoomed,
+ !isVideo && isDragging && styles.imageWrapperDragging,
+ )}
+ onDoubleClick={isVideo ? undefined : handleDoubleClick}
+ onKeyDown={isZoomTarget ? handleImageKeyDown : undefined}
+ onPointerDown={isVideo ? undefined : handlePointerDown}>
+ {isVideo ? (
+ <video
+ src={currentItem.src}
+ aria-label={currentItem.alt}
+ controls
+ autoPlay={hasAutoPlay}
+ {...stylex.props(styles.video)}
+ />
+ ) : (
+ <img
+ src={currentItem.src}
+ alt={currentItem.alt}
+ draggable={false}
+ {...stylex.props(
+ styles.image,
+ isDragging && styles.imageDragging,
+ imageTransform != null &&
+ dynamicStyles.imageTransform(imageTransform),
+ )}
+ />
+ )}
+ </div>
+
+ {currentItem.caption && (
+ <div {...stylex.props(styles.caption)}>
+ {currentItem.caption}
+ </div>
+ )}
+ </div>
+
+ {/* Gallery nav: next — see "prev" above; stays mounted and disabled at
the end of the range instead of unmounting. */}
- {isGallery && (
- <IconButton
- icon={
- <Icon
- icon="chevronRight"
- size="sm"
- color="inherit"
- xstyle={rtlStyles.mirror}
- />
- }
- label={t('@astryx.lightbox.next')}
- variant="ghost"
- isDisabled={!canNext}
- onClick={goToNext}
- xstyle={[styles.navButton, styles.navNext, styles.controlButton]}
- />
- )}
+ {isGallery && (
+ <IconButton
+ icon={
+ <Icon
+ icon="chevronRight"
+ size="sm"
+ color="inherit"
+ xstyle={rtlStyles.mirror}
+ />
+ }
+ label={t('@astryx.lightbox.next')}
+ variant="ghost"
+ isDisabled={!canNext}
+ onClick={goToNext}
+ xstyle={[
+ styles.navButton,
+ styles.navNext,
+ styles.controlButton,
+ ]}
+ />
+ )}
- {/* Gallery counter */}
- {isGallery && mediaArray.length > 1 && (
- <div {...stylex.props(styles.counter)}>
- {index + 1} / {mediaArray.length}
- </div>
- )}
- </div>
+ {/* Gallery counter */}
+ {isGallery && mediaArray.length > 1 && (
+ <div {...stylex.props(styles.counter)}>
+ {index + 1} / {mediaArray.length}
+ </div>
+ )}
+ </div>
+ </LayerContentBoundary>
</LayerDepthProvider>
</dialog>
);
diff --git a/packages/core/src/List/ListContext.tsx b/packages/core/src/List/ListContext.tsx
index ff95d81a3a..7ce456eaf9 100644
--- a/packages/core/src/List/ListContext.tsx
+++ b/packages/core/src/List/ListContext.tsx
@@ -4,13 +4,13 @@
/**
* @file ListContext.tsx
- * @input Uses React createContext
+ * @input Layer-scoped React context
* @output Exports ListContext for sharing density, dividers, marker style,
* and optional inline edge compensation between List and ListItem
* @position Internal context; consumed by List.tsx and ListItem.tsx
*/
-import {createContext} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
export type ListDensity = 'compact' | 'balanced' | 'spacious';
export type ListMarkerStyle = 'none' | 'disc' | 'decimal' | 'circle';
diff --git a/packages/core/src/MetadataList/MetadataListContext.tsx b/packages/core/src/MetadataList/MetadataListContext.tsx
index 145fb108cf..0e02b75870 100644
--- a/packages/core/src/MetadataList/MetadataListContext.tsx
+++ b/packages/core/src/MetadataList/MetadataListContext.tsx
@@ -4,12 +4,12 @@
/**
* @file MetadataListContext.tsx
- * @input Uses React createContext
+ * @input Layer-scoped React context
* @output Exports MetadataListContext for sharing config between MetadataList and MetadataListItem
* @position Internal context; consumed by MetadataList.tsx and MetadataListItem.tsx
*/
-import {createContext} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
export interface MetadataListLabelConfig {
position: 'start' | 'top';
diff --git a/packages/core/src/MobileNav/MobileNav.tsx b/packages/core/src/MobileNav/MobileNav.tsx
index a3d0781fc2..24f39d0c4c 100644
--- a/packages/core/src/MobileNav/MobileNav.tsx
+++ b/packages/core/src/MobileNav/MobileNav.tsx
@@ -58,6 +58,8 @@ import {
type ScrollbarGutterHold,
} from '../hooks/scrollbarGutter';
import {mergeProps, composeEventHandlers} from '../utils';
+import {layerTextReset} from '../Layer/layerTextReset.stylex';
+import {LayerContentBoundary} from '../Layer/layerScopedContext';
import {overlayPaddingReset} from '../Layout/padding.stylex';
import {LayerDepthProvider} from '../Layer/LayerDepthContext';
import {useLayerDismissal} from '../Layer/useLayerDismissal';
@@ -589,6 +591,7 @@ export function MobileNav({
{...mergeProps(
themeProps('mobile-nav', {side: resolvedSide}),
stylex.props(
+ layerTextReset.reset,
styles.dialog,
overlayPaddingReset.reset,
isOpen && styles.open,
@@ -610,39 +613,41 @@ export function MobileNav({
onClick={composeEventHandlers(onClickProp, handleDialogClick)}
onCancel={handleCancel}>
<LayerDepthProvider>
- {/* Drawer panel — tabIndex so showModal() focuses the drawer, not the close button */}
- <div
- tabIndex={-1}
- {...stylex.props(
- styles.drawer,
- dynamicStyles.width(width),
- isStart && styles.drawerStart,
- isStart && isOpen && styles.drawerStartOpen,
- !isStart && styles.drawerEnd,
- !isStart && isOpen && styles.drawerEndOpen,
- )}>
- {/* Header — content + close button */}
+ <LayerContentBoundary>
+ {/* Drawer panel — tabIndex so showModal() focuses the drawer, not the close button */}
<div
- {...stylex.props(styles.header, !header && styles.headerNoTitle)}>
- {typeof header === 'string' ? (
- <Heading level={2} xstyle={styles.headerText}>
- {header}
- </Heading>
- ) : (
- (header ?? null)
- )}
- <Button
- variant="ghost"
- label={t('@astryx.mobileNav.closeNavigation')}
- icon={<Icon icon="close" color="inherit" />}
- onClick={() => onOpenChange(false)}
- isIconOnly
- />
+ tabIndex={-1}
+ {...stylex.props(
+ styles.drawer,
+ dynamicStyles.width(width),
+ isStart && styles.drawerStart,
+ isStart && isOpen && styles.drawerStartOpen,
+ !isStart && styles.drawerEnd,
+ !isStart && isOpen && styles.drawerEndOpen,
+ )}>
+ {/* Header — content + close button */}
+ <div
+ {...stylex.props(styles.header, !header && styles.headerNoTitle)}>
+ {typeof header === 'string' ? (
+ <Heading level={2} xstyle={styles.headerText}>
+ {header}
+ </Heading>
+ ) : (
+ (header ?? null)
+ )}
+ <Button
+ variant="ghost"
+ label={t('@astryx.mobileNav.closeNavigation')}
+ icon={<Icon icon="close" color="inherit" />}
+ onClick={() => onOpenChange(false)}
+ isIconOnly
+ />
+ </div>
+
+ {/* Scrollable content */}
+ <div {...stylex.props(styles.content)}>{children}</div>
</div>
-
- {/* Scrollable content */}
- <div {...stylex.props(styles.content)}>{children}</div>
- </div>
+ </LayerContentBoundary>
</LayerDepthProvider>
</dialog>
);
diff --git a/packages/core/src/NavMenu/NavMenuContext.tsx b/packages/core/src/NavMenu/NavMenuContext.tsx
index 016c99740f..b41680a2be 100644
--- a/packages/core/src/NavMenu/NavMenuContext.tsx
+++ b/packages/core/src/NavMenu/NavMenuContext.tsx
@@ -4,7 +4,7 @@
/**
* @file NavMenuContext.tsx
- * @input Uses React createContext/use
+ * @input Layer-scoped React context/use
* @output Exports NavHeadingCloseContext, NavHeadingMenuContext, and hooks
* @position Context providers; consumed by NavHeadingMenu and NavHeadingMenuItem
*
@@ -13,6 +13,7 @@
*/
import {createContext, use} from 'react';
+import {createLayerScopedContext} from '../Layer/layerScopedContext';
export type NavHeadingMenuSize = 'sm' | 'md' | 'lg';
@@ -43,7 +44,7 @@ export interface NavHeadingMenuContextValue {
}
export const NavHeadingMenuContext =
- createContext<NavHeadingMenuContextValue | null>(null);
+ createLayerScopedContext<NavHeadingMenuContextValue | null>(null);
NavHeadingMenuContext.displayName = 'NavHeadingMenuContext';
export function useNavHeadingMenuContext(): NavHeadingMenuContextValue | null {
diff --git a/packages/core/src/RadioList/RadioList.tsx b/packages/core/src/RadioList/RadioList.tsx
index e147d658b8..da36b36836 100644
--- a/packages/core/src/RadioList/RadioList.tsx
+++ b/packages/core/src/RadioList/RadioList.tsx
@@ -4,7 +4,7 @@
/**
* @file RadioList.tsx
- * @input Uses React useId, useCallback, useRef, createContext, ReactNode, Field, InputStatus
+ * @input Uses React useId, useCallback, useRef, layer-scoped context, ReactNode, Field, InputStatus
* @output Exports RadioList component, RadioListProps, RadioListContext
* @position Core implementation; consumed by index.ts, tested by RadioList.test.tsx
*
@@ -16,8 +16,8 @@
* - /packages/cli/assets/templates/blocks/components/RadioList/ (showcase blocks)
*/
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
import React, {
- createContext,
useCallback,
useId,
useMemo,
diff --git a/packages/core/src/SegmentedControl/SegmentedControlContext.ts b/packages/core/src/SegmentedControl/SegmentedControlContext.ts
index b5b6f45acc..375cdf9a63 100644
--- a/packages/core/src/SegmentedControl/SegmentedControlContext.ts
+++ b/packages/core/src/SegmentedControl/SegmentedControlContext.ts
@@ -4,14 +4,15 @@
/**
* @file SegmentedControlContext.ts
- * @input React createContext, use
+ * @input Layer-scoped React context, use
* @output Exports SegmentedControlContext, useSegmentedControlContext
* @position Context provider; consumed by SegmentedControlItem.tsx
*
* SYNC: When modified, update /packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
*/
-import {createContext, use} from 'react';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
export type SegmentedControlSize = 'sm' | 'md' | 'lg';
export type SegmentedControlLayout = 'hug' | 'fill';
diff --git a/packages/core/src/Selector/SelectorRowLayoutContext.ts b/packages/core/src/Selector/SelectorRowLayoutContext.ts
index 5d3cd9e711..86b3d057f4 100644
--- a/packages/core/src/Selector/SelectorRowLayoutContext.ts
+++ b/packages/core/src/Selector/SelectorRowLayoutContext.ts
@@ -4,7 +4,7 @@
/**
* @file SelectorRowLayoutContext.ts
- * @input React createContext/use
+ * @input Layer-scoped React context/use
* @output Exports the row-layout context and useSelectorRowLayout hook
* @position Internal to the Selector module; read by SelectorOption
*
@@ -15,7 +15,8 @@
* depend on it — a node that ignores this context still cannot grow the row.
*/
-import {createContext, use} from 'react';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
export type SelectorRowLayout = 'stacked' | 'inline';
diff --git a/packages/core/src/SizeContext/SizeContext.ts b/packages/core/src/SizeContext/SizeContext.ts
index 10700cb79f..b0b6a42241 100644
--- a/packages/core/src/SizeContext/SizeContext.ts
+++ b/packages/core/src/SizeContext/SizeContext.ts
@@ -4,7 +4,7 @@
/**
* @file SizeContext.ts
- * @input React createContext, use
+ * @input Layer-scoped React context, use
* @output Exports SizeContext, useSize, ElementSize, SizeProvider
* @position Context provider; consumed by Button, TextInput, TabList, Selector, etc.
*
@@ -13,7 +13,8 @@
* fallback — an explicit `size` prop always wins.
*/
-import {createContext, use} from 'react';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
/**
* Standard element sizes used across interactive components.
diff --git a/packages/core/src/Stepper/StepperContext.ts b/packages/core/src/Stepper/StepperContext.ts
index d585f8c42b..c677212587 100644
--- a/packages/core/src/Stepper/StepperContext.ts
+++ b/packages/core/src/Stepper/StepperContext.ts
@@ -4,7 +4,7 @@
/**
* @file StepperContext.ts
- * @input Uses React createContext/use
+ * @input Layer-scoped React context/use
* @output Exports the public Stepper context hook and package-internal
* coordination used by Stepper and Step
* @position Context for Stepper <-> Step communication
@@ -25,7 +25,8 @@
* - /packages/core/src/Stepper/Stepper.public.test.ts
*/
-import {createContext, use, type Context} from 'react';
+import {use, type Context} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
export type StepperOrientation = 'horizontal' | 'vertical';
export type StepperDensity = 'compact' | 'balanced' | 'spacious';
diff --git a/packages/core/src/TabList/TabListContext.ts b/packages/core/src/TabList/TabListContext.ts
index b2c9b955ae..2424c6ba06 100644
--- a/packages/core/src/TabList/TabListContext.ts
+++ b/packages/core/src/TabList/TabListContext.ts
@@ -4,14 +4,15 @@
/**
* @file TabListContext.ts
- * @input React createContext, use
+ * @input Layer-scoped React context, use
* @output Exports TabListContext, useTabListContext, TabListPattern
* @position Context provider; consumed by Tab.tsx, TabMenu.tsx
*
* SYNC: When modified, update /packages/core/src/TabList/TabList.doc.mjs
*/
-import {createContext, use} from 'react';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
/**
* Size variants for tab list items.
diff --git a/packages/core/src/Table/TableContext.ts b/packages/core/src/Table/TableContext.ts
index 28a36d45ea..c2a03c5424 100644
--- a/packages/core/src/Table/TableContext.ts
+++ b/packages/core/src/Table/TableContext.ts
@@ -4,7 +4,7 @@
/**
* @file TableContext.ts
- * @input React
+ * @input Layer-scoped React context
* @output Exports TableContext and TableContextValue
* @position Context layer; connects Table styling to sub-components (TableRow, TableCell)
*
@@ -15,7 +15,7 @@
* - /packages/core/src/Table/index.ts (exports if types change)
*/
-import {createContext} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
import type {TableVerticalAlign} from './types';
export interface TableContextValue {
diff --git a/packages/core/src/Toast/ToastViewport.tsx b/packages/core/src/Toast/ToastViewport.tsx
index 62dbde6729..60446683e1 100644
--- a/packages/core/src/Toast/ToastViewport.tsx
+++ b/packages/core/src/Toast/ToastViewport.tsx
@@ -4,8 +4,8 @@
/**
* @file ToastViewport.tsx
- * @input Uses React state/effects, ToastContext, useAnnounce, viewport tokens,
- * and placement-derived motion variables
+ * @input Uses React state/effects, ToastContext, content-provider boundary, useAnnounce, viewport tokens,
+ * shared layer text reset, and placement-derived motion variables
* @output Exports the ToastViewport provider, stack, live announcement dispatch,
* focus handoff, safe-area-aware edge gutters, and motion context
* @position Core provider/imperative viewport for useToast()
@@ -29,6 +29,8 @@ import {spacingVars, durationVars, easeVars} from '../theme/tokens.stylex';
import {mergeProps} from '../utils';
import {INTERACTIVE_SELECTORS} from '../hooks/useClickableContainer';
import {useAnnounce} from '../hooks/useAnnounce';
+import {layerTextReset} from '../Layer/layerTextReset.stylex';
+import {LayerContentBoundary} from '../Layer/layerScopedContext';
import {ToastSurface} from './Toast';
import {ToastContext, type ToastContextValue} from './ToastContext';
import type {ToastEntry, ToastPosition, ToastDismissReason} from './types';
@@ -603,21 +605,28 @@ export function ToastViewport({
// Omitted inside dialogs where the viewport is already in a top layer.
popover={isTopLayer ? 'manual' : undefined}
{...mergeProps(
- stylex.props(styles.viewport, styles.viewportInlineSpan, posStyle),
+ stylex.props(
+ layerTextReset.reset,
+ styles.viewport,
+ styles.viewportInlineSpan,
+ posStyle,
+ ),
{
style: Object.keys(insetStyle).length > 0 ? insetStyle : undefined,
},
)}>
- {visibleToasts.map(entry => (
- <ToastRow
- key={entry.id}
- entry={entry}
- isExiting={exitingIds.has(entry.id)}
- isReversed={isReversed}
- onExited={handleExited}
- onDismiss={removeToast}
- />
- ))}
+ <LayerContentBoundary>
+ {visibleToasts.map(entry => (
+ <ToastRow
+ key={entry.id}
+ entry={entry}
+ isExiting={exitingIds.has(entry.id)}
+ isReversed={isReversed}
+ onExited={handleExited}
+ onDismiss={removeToast}
+ />
+ ))}
+ </LayerContentBoundary>
</div>
</ToastContext>
);
diff --git a/packages/core/src/ToggleButton/ToggleButtonGroup.tsx b/packages/core/src/ToggleButton/ToggleButtonGroup.tsx
index 43d97fea36..a49ccd9a46 100644
--- a/packages/core/src/ToggleButton/ToggleButtonGroup.tsx
+++ b/packages/core/src/ToggleButton/ToggleButtonGroup.tsx
@@ -4,7 +4,7 @@
/**
* @file ToggleButtonGroup.tsx
- * @input Uses React Context, ToggleButton children
+ * @input Layer-scoped React context, ToggleButton children
* @output Exports ToggleButtonGroup component and types
* @position Groups toggle buttons for single or multi-select behavior
*
@@ -18,7 +18,8 @@
* - /packages/cli/assets/templates/blocks/components/ToggleButton/ (showcase blocks)
*/
-import {createContext, useCallback, use, useMemo, type ReactNode} from 'react';
+import {useCallback, use, useMemo, type ReactNode} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
import * as stylex from '@stylexjs/stylex';
import {spacingVars} from '../theme/tokens.stylex';
import type {ButtonSize} from '../Button';
diff --git a/packages/core/src/TopNav/TopNavContext.ts b/packages/core/src/TopNav/TopNavContext.ts
index 90b7ed80f0..7ebe3099c6 100644
--- a/packages/core/src/TopNav/TopNavContext.ts
+++ b/packages/core/src/TopNav/TopNavContext.ts
@@ -2,15 +2,21 @@
'use client';
-import {createContext, use} from 'react';
+/**
+ * @file TopNavContext.ts
+ * @input Layer-scoped React context
+ * @output TopNavSlotContext and useTopNavSlot
+ * @position Navigation slot presentation defaults
+ */
-export type TopNavSlot = 'start' | 'center' | 'end';
+import {use} from 'react';
+import {createLayerScopedContext as createContext} from '../Layer/layerScopedContext';
+export type TopNavSlot = 'start' | 'center' | 'end';
export const TopNavSlotContext = createContext<TopNavSlot>('start');
TopNavSlotContext.displayName = 'TopNavSlotContext';
-
export function useTopNavSlot(): TopNavSlot {
return use(TopNavSlotContext);
}
diff --git a/packages/lab/src/Drawer/Drawer.tsx b/packages/lab/src/Drawer/Drawer.tsx
index b78b6eb759..2a29412f2e 100644
--- a/packages/lab/src/Drawer/Drawer.tsx
+++ b/packages/lab/src/Drawer/Drawer.tsx
@@ -4,7 +4,7 @@
/**
* @file Drawer.tsx
- * @input Uses React, StyleX, theme tokens, Icon/IconButton, useScrollLock/useDrawerDialogPresence, BaseProps, mergeProps/mergeRefs, themeProps
+ * @input Uses React, StyleX, theme tokens and text defaults, Icon/IconButton, useScrollLock/useDrawerDialogPresence, BaseProps, mergeProps/mergeRefs, themeProps
* @output Exports Drawer component and DrawerProps
* @position Lab implementation; consumed by index.ts, tested by Drawer.test.tsx, demonstrated in Storybook
*
@@ -60,6 +60,8 @@ import {
easeVars,
shadowVars,
spacingVars,
+ typeScaleVars,
+ typographyVars,
} from '@astryxdesign/core/theme/tokens.stylex';
import {Icon} from '@astryxdesign/core/Icon';
import {IconButton} from '@astryxdesign/core/IconButton';
@@ -130,6 +132,23 @@ const MOBILE_WIDTH_FULL = '100dvw';
const styles = stylex.create({
dialog: {
+ // Keep the layer text boundary local rather than exposing Core styling internals.
+ fontFamily: typographyVars['--font-family-body'],
+ fontSize: typeScaleVars['--text-body-size'],
+ fontWeight: typeScaleVars['--text-body-weight'],
+ lineHeight: typeScaleVars['--text-body-leading'],
+ fontStyle: 'normal',
+ textAlign: 'start',
+ textAlignLast: 'auto',
+ textIndent: 0,
+ textTransform: 'none',
+ letterSpacing: 'normal',
+ wordSpacing: 'normal',
+ textShadow: 'none',
+ whiteSpace: 'normal',
+ wordBreak: 'normal',
+ overflowWrap: 'normal',
+ hyphens: 'manual',
// Reset native <dialog> defaults — the dialog element IS the panel.
position: 'fixed',
margin: 0,