An open source design system that's fully customizable and agent ready
TypeScript
fix(layer): declare body type on the layer instead of inheriting it (#5064)
Cindy Zhang77b013d2afbb
diff --git a/.changeset/layer-own-body-typography.md b/.changeset/layer-own-body-typography.mdnew file mode 100644index 0000000000..940e91814e--- /dev/null+++ b/.changeset/layer-own-body-typography.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Floating layers now declare their own body type instead of inheriting it. The layer container already set `font-family`; it now sets `font-size` and `line-height` from `--text-body-size` / `--text-body-leading` alongside it. A layer is hosted wherever its trigger sits, so any content that did not set its own size took the ambient one — the same Tooltip, Popover or HoverCard rendered at 13px from a caption and at 20px from a lede. Content that goes through `Text`, or sets a size itself (Tooltip's label, DropdownMenu items, NavMenu headings), is unaffected: those already declared their own and still win. Anything that was relying on inheriting a non-body size now renders at the body size and should set one explicitly.++@cixzhangdiff --git a/packages/core/src/Layer/useLayer.test.tsx b/packages/core/src/Layer/useLayer.test.tsxindex 3590c55402..f44e9b1935 100644--- a/packages/core/src/Layer/useLayer.test.tsx+++ b/packages/core/src/Layer/useLayer.test.tsx@@ -500,6 +500,20 @@ describe('useLayer', () => {});describe('when the Popover API is supported', () => {+ it('declares body type instead of inheriting the host context', () => {+ const {container} = render(+ <div style={{fontSize: '30px', lineHeight: '3'}}>+ <LayerHarness onReady={() => {}} />+ </div>,+ );++ const layer = container.querySelector('[popover]') as HTMLElement;+ expect(layer).toHaveStyle({+ fontSize: 'var(--text-body-size)',+ lineHeight: 'var(--text-body-leading)',+ });+ });+it('calls showPopover/hidePopover on show/hide', () => {const showSpy = vi.fn();const hideSpy = vi.fn();diff --git a/packages/core/src/Layer/useLayer.tsx b/packages/core/src/Layer/useLayer.tsxindex 42cb0ca5aa..3a7289130b 100644--- a/packages/core/src/Layer/useLayer.tsx+++ b/packages/core/src/Layer/useLayer.tsx@@ -28,7 +28,7 @@ import type {StyleXStyles} from '@stylexjs/stylex';import {createPortal} from 'react-dom';import {addAnchorName, removeAnchorName} from './anchorName';import {resolveLayerPortalTarget} from './layerHost';-import {typographyVars} from '../theme/tokens.stylex';+import {typeScaleVars, typographyVars} from '../theme/tokens.stylex';const styles = stylex.create({// Base reset for all layers@@ -44,7 +44,12 @@ 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',},