Skip to content

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

TypeScript

feat(layer): derive layer clearance from the resolved placement (offset) (#4951)

Cindy Zhangc45c29725860
diff --git a/.changeset/layer-offset-render-prop.md b/.changeset/layer-offset-render-prop.md
new file mode 100644
index 0000000000..2af64643f2
--- /dev/null
+++ b/.changeset/layer-offset-render-prop.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] useLayer takes an `offset` for clearance from the anchor, derived from the resolved placement, and the layer wrappers stop hand-rolling it (#4803)
+@cixzhang
diff --git a/apps/storybook/stories/Layer.stories.tsx b/apps/storybook/stories/Layer.stories.tsx
index eae5ba06d1..c44953e873 100644
--- a/apps/storybook/stories/Layer.stories.tsx
+++ b/apps/storybook/stories/Layer.stories.tsx
@@ -66,6 +66,61 @@ export const ContextMode: Story = {
render: () => <ContextModeDemo />,
};
+function OffsetDemo() {
+ const [placement, setPlacement] = useState<
+ 'above' | 'below' | 'start' | 'end'
+ >('end');
+ const flush = useLayer({mode: 'context', lightDismiss: true});
+ const spaced = useLayer({mode: 'context', lightDismiss: true});
+
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: 16}}>
+ <div style={{display: 'flex', gap: 8}}>
+ {(['above', 'below', 'start', 'end'] as const).map(p => (
+ <Button
+ key={p}
+ label={p}
+ variant={placement === p ? 'primary' : 'secondary'}
+ onClick={() => setPlacement(p)}
+ />
+ ))}
+ </div>
+ <div {...stylex.props(styles.demoArea)} style={{gap: 120}}>
+ <div>
+ <Button
+ ref={flush.ref}
+ label="offset: 0"
+ onClick={() => (flush.isOpen ? flush.hide() : flush.show())}
+ />
+ {flush.render(
+ <div {...stylex.props(styles.popoverContent)}>
+ <Text type="body">Flush against the anchor</Text>
+ </div>,
+ {placement, alignment: 'center'},
+ )}
+ </div>
+ <div>
+ <Button
+ ref={spaced.ref}
+ label="offset: 12"
+ onClick={() => (spaced.isOpen ? spaced.hide() : spaced.show())}
+ />
+ {spaced.render(
+ <div {...stylex.props(styles.popoverContent)}>
+ <Text type="body">12px of clearance, on either side</Text>
+ </div>,
+ {placement, alignment: 'center', offset: 12},
+ )}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+export const Offset: Story = {
+ render: () => <OffsetDemo />,
+};
+
function PlacementDemo() {
const [placement, setPlacement] = useState<
'above' | 'below' | 'start' | 'end'
@@ -156,7 +211,6 @@ function LayerProviderDemo() {
<LayerProvider toast={{position: 'topEnd', maxVisible: 3}}>
<div style={{padding: 16}}>
<Text type="body">
-
LayerProvider wraps your app to configure layer systems (toast
positioning, max visible toasts). It is optional; hooks fall back to
defaults when no provider exists.
diff --git a/packages/core/src/Chat/useTriggerMenu.tsx b/packages/core/src/Chat/useTriggerMenu.tsx
index d72de2b7c6..c7afad9f6b 100644
--- a/packages/core/src/Chat/useTriggerMenu.tsx
+++ b/packages/core/src/Chat/useTriggerMenu.tsx
@@ -110,10 +110,6 @@ const styles = stylex.create({
popoverSurface: {
minWidth: '180px',
},
- popoverGap: {
- marginBlockStart: spacingVars['--spacing-1'],
- marginBlockEnd: spacingVars['--spacing-1'],
- },
item: {
boxSizing: 'border-box',
display: 'flex',
@@ -711,7 +707,8 @@ export function useTriggerMenu(
{
placement: 'above',
alignment: 'start',
- xstyle: [styles.popoverSurface, styles.popoverGap],
+ offset: spacingVars['--spacing-1'],
+ xstyle: styles.popoverSurface,
},
);
}, [popover, listboxId, state, selectItem, getItemId, t]);
diff --git a/packages/core/src/ComplexSelector/ComplexSelector.test.tsx b/packages/core/src/ComplexSelector/ComplexSelector.test.tsx
index 23b111afd5..35394113f2 100644
--- a/packages/core/src/ComplexSelector/ComplexSelector.test.tsx
+++ b/packages/core/src/ComplexSelector/ComplexSelector.test.tsx
@@ -117,18 +117,14 @@ describe('ComplexSelector', () => {
await user.click(screen.getByRole('button', {name: 'Fruit blend'}));
const popup = document.querySelector('[popover]') as HTMLElement;
expect(popup).not.toBeNull();
- const style = getComputedStyle(popup);
- // Only the leading edge (marginBlockStart) had clearance, which is
- // correct for a popup that opens downward but leaves zero clearance
- // when the same popup opens upward (placement="above") — the trailing
- // edge is what's nearest the trigger in that orientation. Popover (built
- // on the same usePopover/useLayer pair) sets both edges via its own
- // `gap` style, which is what this mirrors. jsdom doesn't resolve the
- // marginBlockStart/marginBlockEnd logical computed-style properties for
- // this element (both return '' regardless), so assert on the equivalent
- // physical properties instead, which do resolve correctly here.
- expect(style.marginTop).toBe('var(--spacing-1)');
- expect(style.marginBottom).toBe('var(--spacing-1)');
+ // Both edges, not just the leading one: the trailing edge is what faces
+ // the trigger when the same popup opens upward (placement="above") or is
+ // flipped by position-try-fallbacks. useLayer's `offset` sets both from
+ // the resolved placement; jsdom resolves neither the var indirection nor
+ // logical margins, so read the debug-mode declarations it emits.
+ const blockStart = popup.style.getPropertyValue('--x-marginBlockStart');
+ expect(blockStart).not.toBe('');
+ expect(popup.style.getPropertyValue('--x-marginBlockEnd')).toBe(blockStart);
});
it('runs changeAction through the provided onChange helper', async () => {
diff --git a/packages/core/src/ComplexSelector/ComplexSelector.tsx b/packages/core/src/ComplexSelector/ComplexSelector.tsx
index d6b043541e..841a32ab03 100644
--- a/packages/core/src/ComplexSelector/ComplexSelector.tsx
+++ b/packages/core/src/ComplexSelector/ComplexSelector.tsx
@@ -121,14 +121,6 @@ const styles = stylex.create({
},
popover: {
minWidth: 'anchor-size(width)',
- // Both edges, not just the start: this popup can open either direction
- // (`placement="below"` or `"above"`), and only marginBlockStart having a
- // value meant the clearance vanished when it opened upward, since that's
- // the edge nearest the trigger in that orientation. Popover (built on
- // the same usePopover/useLayer pair) sets both edges for the same
- // reason — see its `gap` style.
- marginBlockStart: spacingVars['--spacing-1'],
- marginBlockEnd: spacingVars['--spacing-1'],
},
content: {
boxSizing: 'border-box',
@@ -408,6 +400,7 @@ export function ComplexSelector<Value>({
{popover.render(content, {
placement,
alignment: 'start',
+ offset: spacingVars['--spacing-1'],
xstyle: [styles.popover, layerAnimations[placement]],
})}
</>
diff --git a/packages/core/src/DropdownMenu/DropdownMenu.tsx b/packages/core/src/DropdownMenu/DropdownMenu.tsx
index c79adb9df6..49ab5470d4 100644
--- a/packages/core/src/DropdownMenu/DropdownMenu.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenu.tsx
@@ -87,14 +87,6 @@ const styles = stylex.create({
popover: {
minWidth: 'anchor-size(width)',
},
- popoverBlockGap: {
- marginBlockStart: spacingVars['--spacing-1'],
- marginBlockEnd: spacingVars['--spacing-1'],
- },
- popoverInlineGap: {
- marginInlineStart: spacingVars['--spacing-1'],
- marginInlineEnd: spacingVars['--spacing-1'],
- },
popoverCustomWidth: (width: string | number) => ({
minWidth: typeof width === 'number' ? `${width}px` : width,
}),
@@ -472,11 +464,6 @@ export function DropdownMenu({
const popoverXstyle = menuWidth
? styles.popoverCustomWidth(menuWidth)
: styles.popover;
- const popoverGapStyle =
- placement === 'above' || placement === 'below'
- ? styles.popoverBlockGap
- : styles.popoverInlineGap;
-
// Context for compound items
const contextValue = useMemo<DropdownMenuContextValue>(
() => ({closeMenu, menuSize}),
@@ -542,7 +529,8 @@ export function DropdownMenu({
{
placement,
alignment,
- xstyle: [popoverXstyle, popoverGapStyle, layerAnimations[placement]],
+ offset: spacingVars['--spacing-1'],
+ xstyle: [popoverXstyle, layerAnimations[placement]],
},
)}
</>
diff --git a/packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx b/packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx
index dee734f243..131ffd0dc2 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx
@@ -147,14 +147,9 @@ const flyoutStyles = stylex.create({
},
popover: {
minWidth: '160px',
- // Small inline gap so the flyout doesn't sit flush against the parent menu.
- marginInlineStart: spacingVars['--spacing-1'],
- marginInlineEnd: spacingVars['--spacing-1'],
},
popoverCustomWidth: (width: string | number) => ({
minWidth: typeof width === 'number' ? `${width}px` : width,
- marginInlineStart: spacingVars['--spacing-1'],
- marginInlineEnd: spacingVars['--spacing-1'],
}),
});
@@ -559,6 +554,7 @@ export function DropdownMenuSubMenu(
{
placement: 'end',
alignment: 'start',
+ offset: spacingVars['--spacing-1'],
xstyle: [popoverXstyle, layerAnimations.end],
},
)}
diff --git a/packages/core/src/HoverCard/useHoverCard.tsx b/packages/core/src/HoverCard/useHoverCard.tsx
index cbedb4c091..cb369ef86f 100644
--- a/packages/core/src/HoverCard/useHoverCard.tsx
+++ b/packages/core/src/HoverCard/useHoverCard.tsx
@@ -15,7 +15,6 @@
import {
useCallback,
useEffect,
- useMemo,
useRef,
type ReactNode,
type RefCallback,
@@ -45,18 +44,6 @@ const styles = stylex.create({
boxShadow: shadowVars['--shadow-med'],
},
// Position-based margin styles
- marginBlock: {
- marginBlockStart: spacingVars['--spacing-1'],
- marginBlockEnd: spacingVars['--spacing-1'],
- marginInlineStart: 0,
- marginInlineEnd: 0,
- },
- marginInline: {
- marginBlockStart: 0,
- marginBlockEnd: 0,
- marginInlineStart: spacingVars['--spacing-1'],
- marginInlineEnd: spacingVars['--spacing-1'],
- },
// Content wrapper for padding and mouse events.
// `display: block` keeps the wrapper a block box even though it renders as a
// `span` (the layer uses inline-safe phrasing markup so it is valid inside a
@@ -265,22 +252,13 @@ export function useHoverCard(options: HoverCardOptions = {}): HoverCardReturn {
onHide,
} = options;
- // Select margin style based on placement axis
- const marginStyle =
- placement === 'above' || placement === 'below'
- ? styles.marginBlock
- : styles.marginInline;
-
const layer = useLayer({
mode: 'context',
onShow,
onHide,
});
- const popoverXstyle = useMemo(
- () => [styles.container, marginStyle],
- [marginStyle],
- );
+ const popoverXstyle = styles.container;
const showTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const hideTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
@@ -472,6 +450,7 @@ export function useHoverCard(options: HoverCardOptions = {}): HoverCardReturn {
const renderProps = {
placement: renderPlacement,
alignment: props?.alignment ?? alignment,
+ offset: spacingVars['--spacing-1'],
// A named dialog when a label is provided; otherwise a group. A group
// may validly be unnamed, an unnamed dialog may not — and hover cards
// are non-modal, so group is honest semantics without a name.
diff --git a/packages/core/src/Layer/useLayer.doc.mjs b/packages/core/src/Layer/useLayer.doc.mjs
index 1d2da91337..855fe727a6 100644
--- a/packages/core/src/Layer/useLayer.doc.mjs
+++ b/packages/core/src/Layer/useLayer.doc.mjs
@@ -79,7 +79,7 @@ export const docs = {
name: 'render',
type: '(children: ReactNode, props: ContextRenderProps | FixedRenderProps) => ReactNode',
description:
- 'Render function for the popover element. Pass placement/alignment in context mode or x/y in fixed mode. Placement/alignment are logical: they map to the self-* position-area keyword family, which resolves against the popover\'s own inherited direction, so RTL contexts mirror automatically in pure CSS. Pass `positioning: "custom"` in context mode to author position styles yourself via `style` (e.g. explicit anchor() insets or an anchor-size() cover): the hook keeps the popover behavior and position-anchor wiring but derives no position styles, including the automatic RTL mirroring, which becomes your responsibility. In context mode, pass `as: "span"` to render an inline-safe layer (e.g. inside a paragraph). The layer renders inline in the React tree; the Popover API promotes it to the top layer when shown, so it escapes ancestor clipping and stacking without a portal. When the layer would overflow the viewport, position-try fallbacks flip it to the opposite side; centered layers additionally slide along the alignment axis (span fallbacks) so they stay on-screen near viewport edges.',
+ 'Render function for the popover element. Pass placement/alignment in context mode or x/y in fixed mode. Placement/alignment are logical: they map to the self-* position-area keyword family, which resolves against the popover\'s own inherited direction, so RTL contexts mirror automatically in pure CSS. Pass `positioning: "custom"` in context mode to author position styles yourself via `style` (e.g. explicit anchor() insets or an anchor-size() cover): the hook keeps the popover behavior and position-anchor wiring but derives no position styles, including the automatic RTL mirroring, which becomes your responsibility. Pass `offset` (a CSS length; a number is px) in context mode for clearance from the anchor: it applies to both edges of the placement axis, so the gap survives a flip. Layers are flush by default. In context mode, pass `as: "span"` to render an inline-safe layer (e.g. inside a paragraph). The layer renders inline in the React tree; the Popover API promotes it to the top layer when shown, so it escapes ancestor clipping and stacking without a portal. When the layer would overflow the viewport, position-try fallbacks flip it to the opposite side; centered layers additionally slide along the alignment axis (span fallbacks) so they stay on-screen near viewport edges.',
},
],
usage: {
@@ -131,7 +131,7 @@ export const docsDense = {
hide: 'hide layer.',
isOpen: 'whether layer is open.',
id: 'unique ARIA id.',
- render: 'renders popover element; pass placement/alignment or x/y. Placement/alignment logical: mapped to self-* position-area keywords resolved against the popover\'s inherited direction (RTL mirrors in pure CSS). `positioning: "custom"` (context mode) = author position styles yourself via `style`; keeps popover behavior + position-anchor wiring, derives nothing (incl. RTL mirroring, which becomes yours). Context mode accepts `as: "span"` for inline-safe layers. Renders inline; the Popover API top layer escapes clipping/stacking without a portal. Viewport overflow: flips to opposite side; centered layers also slide along the alignment axis (span fallbacks).',
+ render: 'renders popover element; pass placement/alignment or x/y. Placement/alignment logical: mapped to self-* position-area keywords resolved against the popover\'s inherited direction (RTL mirrors in pure CSS). `positioning: "custom"` (context mode) = author position styles yourself via `style`; keeps popover behavior + position-anchor wiring, derives nothing (incl. RTL mirroring, which becomes yours). `offset` (context mode) = clearance from the anchor as a CSS length (number = px), applied to both edges of the placement axis so it survives a flip; layers are flush by default. Context mode accepts `as: "span"` for inline-safe layers. Renders inline; the Popover API top layer escapes clipping/stacking without a portal. Viewport overflow: flips to opposite side; centered layers also slide along the alignment axis (span fallbacks).',
},
usage: {
description:
diff --git a/packages/core/src/Layer/useLayer.test.tsx b/packages/core/src/Layer/useLayer.test.tsx
index 5608ac9783..4700f7cb60 100644
--- a/packages/core/src/Layer/useLayer.test.tsx
+++ b/packages/core/src/Layer/useLayer.test.tsx
@@ -440,6 +440,91 @@ describe('useLayer context positioning', () => {
});
});
+ describe('offset', () => {
+ function OffsetHarness({
+ placement,
+ offset,
+ positioning,
+ }: {
+ placement?: LayerPlacement;
+ offset?: number | string;
+ positioning?: 'anchor' | 'custom';
+ }) {
+ const layer = useLayer({mode: 'context'});
+ return (
+ <>
+ <button type="button" ref={layer.ref} onClick={layer.show}>
+ trigger
+ </button>
+ {layer.render(<span>content</span>, {
+ placement,
+ offset,
+ positioning,
+ })}
+ </>
+ );
+ }
+
+ // Debug-mode StyleX variable names for the dynamic offset style, as in
+ // Grid.test.tsx. jsdom resolves neither the var indirection nor logical
+ // margin properties, so the declarations themselves are the assertion.
+ async function openAndGetOffsets(ui: React.ReactElement) {
+ const user = userEvent.setup();
+ const {container, getByRole} = render(ui);
+ await user.click(getByRole('button', {name: 'trigger'}));
+ const el = container.querySelector('[popover]') as HTMLElement;
+ const read = (prop: string) => el.style.getPropertyValue(`--x-${prop}`);
+ return {
+ blockStart: read('marginBlockStart'),
+ blockEnd: read('marginBlockEnd'),
+ inlineStart: read('marginInlineStart'),
+ inlineEnd: read('marginInlineEnd'),
+ };
+ }
+
+ const NONE = {blockStart: '', blockEnd: '', inlineStart: '', inlineEnd: ''};
+
+ it('is flush by default', async () => {
+ expect(await openAndGetOffsets(<OffsetHarness placement="below" />)).toEqual(
+ NONE,
+ );
+ });
+
+ // Both edges of the axis, so the gap survives a position-try-fallbacks
+ // flip to the opposite side (#4803).
+ it('clears both block edges for a block placement', async () => {
+ expect(
+ await openAndGetOffsets(<OffsetHarness placement="above" offset={8} />),
+ ).toEqual({...NONE, blockStart: '8px', blockEnd: '8px'});
+ });
+
+ it('clears both inline edges for an inline placement', async () => {
+ expect(
+ await openAndGetOffsets(<OffsetHarness placement="end" offset={8} />),
+ ).toEqual({...NONE, inlineStart: '8px', inlineEnd: '8px'});
+ });
+
+ it('takes a CSS length string', async () => {
+ expect(
+ await openAndGetOffsets(
+ <OffsetHarness placement="below" offset="var(--spacing-1)" />,
+ ),
+ ).toEqual({
+ ...NONE,
+ blockStart: 'var(--spacing-1)',
+ blockEnd: 'var(--spacing-1)',
+ });
+ });
+
+ it('is ignored under custom positioning, which owns its own insets', async () => {
+ expect(
+ await openAndGetOffsets(
+ <OffsetHarness placement="below" offset={8} positioning="custom" />,
+ ),
+ ).toEqual(NONE);
+ });
+ });
+
it('fixed mode emits no anchor-positioning styles', async () => {
function FixedHarness() {
const layer = useLayer({mode: 'fixed'});
diff --git a/packages/core/src/Layer/useLayer.tsx b/packages/core/src/Layer/useLayer.tsx
index 024f62894f..5e4e1744b1 100644
--- a/packages/core/src/Layer/useLayer.tsx
+++ b/packages/core/src/Layer/useLayer.tsx
@@ -50,6 +50,18 @@ const styles = stylex.create({
fixed: {
position: 'fixed',
},
+ // Clearance from the anchor. Set on BOTH edges of the placement axis, not
+ // just the one facing the anchor: `position-try-fallbacks` can flip the
+ // layer to the opposite side at paint time, and a single-edge margin then
+ // lands on the far side and the gap vanishes (#4803).
+ offsetBlock: (offset: string) => ({
+ marginBlockStart: offset,
+ marginBlockEnd: offset,
+ }),
+ offsetInline: (offset: string) => ({
+ marginInlineStart: offset,
+ marginInlineEnd: offset,
+ }),
});
/**
@@ -94,6 +106,20 @@ export interface ContextRenderProps {
* is `'custom'`.
*/
alignment?: LayerAlignment;
+ /**
+ * Clearance between the layer and its anchor, as a CSS length (a number is
+ * treated as `px`). Applied along the placement axis and flip-safe, so the
+ * gap survives a `position-try-fallbacks` flip to the opposite side.
+ *
+ * Layers sit flush by default: the hook zeroes the UA margins so anchor
+ * positioning has a clean box, and clearance is a deliberate choice per
+ * surface. `var(--spacing-1)` is the system's standard clearance.
+ *
+ * Ignored when `positioning` is `'custom'` — that mode owns its own insets.
+ *
+ * @default 0
+ */
+ offset?: number | string;
/**
* ARIA role applied to the popover container (e.g. `'tooltip'`). Lets
* consumers complete the ARIA pattern and gives test tooling a stable,
@@ -284,6 +310,10 @@ export interface FixedLayerReturn {
render: (children: ReactNode, props: FixedRenderProps) => ReactNode;
}
+function toCssLength(value: number | string): string {
+ return typeof value === 'number' ? `${value}px` : value;
+}
+
/**
* Map logical placement/alignment to a CSS position-area value.
*
@@ -530,6 +560,7 @@ export function useLayer(
placement = 'above',
alignment = 'center',
positioning = 'anchor',
+ offset,
role,
'aria-label': ariaLabel,
xstyle,
@@ -555,7 +586,14 @@ export function useLayer(
),
};
- const stylexResult = stylex.props(styles.base, xstyle);
+ const offsetStyle =
+ positioning === 'anchor' && offset
+ ? placement === 'above' || placement === 'below'
+ ? styles.offsetBlock(toCssLength(offset))
+ : styles.offsetInline(toCssLength(offset))
+ : null;
+
+ const stylexResult = stylex.props(styles.base, offsetStyle, xstyle);
const combinedClassName = extraClassName
? `${extraClassName} ${stylexResult.className ?? ''}`
: stylexResult.className;
diff --git a/packages/core/src/MultiSelector/MultiSelector.tsx b/packages/core/src/MultiSelector/MultiSelector.tsx
index 557a0bce15..0e4e7c1897 100644
--- a/packages/core/src/MultiSelector/MultiSelector.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.tsx
@@ -269,7 +269,6 @@ const styles = stylex.create({
// Popover container (for anchor positioning)
popover: {
minWidth: 'anchor-size(width)',
- marginBlockStart: spacingVars['--spacing-1'],
},
// Search field. The inner TextInput owns the border, focus ring, magnifier
@@ -1624,6 +1623,7 @@ export function MultiSelector<T extends MultiSelectorOptionType>({
{
placement: 'below',
alignment: 'start',
+ offset: spacingVars['--spacing-1'],
xstyle: styles.popover,
},
)}
diff --git a/packages/core/src/Popover/Popover.tsx b/packages/core/src/Popover/Popover.tsx
index eb2fda32e1..e676dd2304 100644
--- a/packages/core/src/Popover/Popover.tsx
+++ b/packages/core/src/Popover/Popover.tsx
@@ -250,10 +250,6 @@ const styles = stylex.create({
paddingInlineStart: spacingVars['--spacing-3'],
paddingInlineEnd: spacingVars['--spacing-3'],
},
- gap: {
- marginBlockStart: spacingVars['--spacing-1'],
- marginBlockEnd: spacingVars['--spacing-1'],
- },
customWidth: (width: string | number) => ({
width: typeof width === 'number' ? `${width}px` : width,
}),
@@ -529,7 +525,8 @@ export function Popover({
{
placement,
alignment,
- xstyle: [popoverXstyle, styles.gap, layerAnimations[placement]],
+ offset: spacingVars['--spacing-1'],
+ xstyle: [popoverXstyle, layerAnimations[placement]],
},
)}
</>
@@ -565,7 +562,8 @@ export function Popover({
{
placement,
alignment,
- xstyle: [popoverXstyle, styles.gap, layerAnimations[placement]],
+ offset: spacingVars['--spacing-1'],
+ xstyle: [popoverXstyle, layerAnimations[placement]],
},
)}
</>
@@ -594,7 +592,8 @@ export function Popover({
{
placement,
alignment,
- xstyle: [popoverXstyle, styles.gap, layerAnimations[placement]],
+ offset: spacingVars['--spacing-1'],
+ xstyle: [popoverXstyle, layerAnimations[placement]],
},
)}
</>
diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsx
index f286e90f9e..9bcb8f7371 100644
--- a/packages/core/src/PowerSearch/PowerSearch.tsx
+++ b/packages/core/src/PowerSearch/PowerSearch.tsx
@@ -104,7 +104,6 @@ const popoverLayerStyles = stylex.create({
layer: {
width: 'anchor-size(width)',
minWidth: 400,
- marginTop: spacingVars['--spacing-1'],
},
});
@@ -1053,6 +1052,7 @@ export function PowerSearch({
{popover.render(popoverContent, {
placement: 'below',
alignment: 'start',
+ offset: spacingVars['--spacing-1'],
xstyle: [popoverLayerStyles.layer, layerAnimations.below],
})}
</>
diff --git a/packages/core/src/Tooltip/useTooltip.tsx b/packages/core/src/Tooltip/useTooltip.tsx
index 917e9981ac..45ad4d3373 100644
--- a/packages/core/src/Tooltip/useTooltip.tsx
+++ b/packages/core/src/Tooltip/useTooltip.tsx
@@ -15,7 +15,6 @@
import {
useCallback,
useEffect,
- useMemo,
useRef,
type ReactNode,
type RefCallback,
@@ -57,18 +56,6 @@ const styles = stylex.create({
lineHeight: typeScaleVars['--text-body-leading'],
},
// Position-based margin styles
- marginBlock: {
- marginBlockStart: spacingVars['--spacing-1'],
- marginBlockEnd: spacingVars['--spacing-1'],
- marginInlineStart: 0,
- marginInlineEnd: 0,
- },
- marginInline: {
- marginBlockStart: 0,
- marginBlockEnd: 0,
- marginInlineStart: spacingVars['--spacing-1'],
- marginInlineEnd: spacingVars['--spacing-1'],
- },
// Content wrapper for padding
content: {
paddingBlockStart: spacingVars['--spacing-1'],
@@ -261,22 +248,13 @@ export function useTooltip(options: TooltipOptions = {}): TooltipReturn {
onHide,
} = options;
- // Select margin style based on placement axis
- const marginStyle =
- placement === 'above' || placement === 'below'
- ? styles.marginBlock
- : styles.marginInline;
-
const layer = useLayer({
mode: 'context',
onShow,
onHide,
});
- const popoverXstyle = useMemo(
- () => [styles.container, marginStyle],
- [marginStyle],
- );
+ const popoverXstyle = styles.container;
const showTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const hideTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
@@ -498,6 +476,7 @@ export function useTooltip(options: TooltipOptions = {}): TooltipReturn {
const renderProps = {
placement: renderPlacement,
alignment: props?.alignment ?? alignment,
+ offset: spacingVars['--spacing-1'],
role: 'tooltip',
xstyle: [popoverXstyle, layerAnimations[renderPlacement]],
className: themeProps('tooltip').className,
diff --git a/packages/core/src/TopNav/TopNavMenu.tsx b/packages/core/src/TopNav/TopNavMenu.tsx
index 3bfb3abf4e..3aeef4ae4a 100644
--- a/packages/core/src/TopNav/TopNavMenu.tsx
+++ b/packages/core/src/TopNav/TopNavMenu.tsx
@@ -107,9 +107,6 @@ const styles = stylex.create({
minWidth: 280,
padding: spacingVars['--spacing-1'],
},
- menuOffset: {
- marginBlockStart: spacingVars['--spacing-1'],
- },
menuItem: {
display: 'flex',
alignItems: 'center',
@@ -343,7 +340,6 @@ export function TopNavMenu({
// wrapper would announce an unnamed dialog around the menu and make the
// trigger claim aria-haspopup="dialog" for menu content (see TabMenu).
role: 'none',
- xstyle: styles.menuOffset,
});
const {triggerProps, contentProps, menuRef, setTriggerEl} =
@@ -550,7 +546,7 @@ export function TopNavMenu({
{
placement: 'below',
alignment: slot,
- xstyle: styles.menuOffset,
+ offset: spacingVars['--spacing-1'],
},
)}
</>
diff --git a/packages/core/src/Typeahead/BaseTypeahead.tsx b/packages/core/src/Typeahead/BaseTypeahead.tsx
index 28f0901c44..d0368829c8 100644
--- a/packages/core/src/Typeahead/BaseTypeahead.tsx
+++ b/packages/core/src/Typeahead/BaseTypeahead.tsx
@@ -226,10 +226,6 @@ const styles = stylex.create({
popover: {
minWidth: 'anchor-size(width)',
},
- popoverGap: {
- marginBlockStart: spacingVars['--spacing-1'],
- marginBlockEnd: spacingVars['--spacing-1'],
- },
item: {
boxSizing: 'border-box',
display: 'flex',
@@ -865,7 +861,8 @@ export const BaseTypeahead = function BaseTypeahead<T extends SearchableItem>({
{
placement: 'below',
alignment: 'start',
- xstyle: [styles.popover, styles.popoverGap],
+ offset: spacingVars['--spacing-1'],
+ xstyle: styles.popover,
},
)}
</>