An open source design system that's fully customizable and agent ready
TypeScript
fix(ComplexSelector): keep popup clearance when placement="above" (#4861)
Ojas Mutreja95ec092bc404
diff --git a/.changeset/complex-selector-popup-above-clearance.md b/.changeset/complex-selector-popup-above-clearance.mdnew file mode 100644index 0000000000..f1fb113a82--- /dev/null+++ b/.changeset/complex-selector-popup-above-clearance.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `ComplexSelector`'s popup now keeps its 4px clearance from the trigger when `placement="above"`, matching `placement="below"` and `Popover`. The popup's margin was set on `marginBlockStart` only, which is correct for a popup opening downward but leaves zero clearance on the edge that matters when it opens upward.++@HelloOjasMutrejadiff --git a/packages/core/src/ComplexSelector/ComplexSelector.test.tsx b/packages/core/src/ComplexSelector/ComplexSelector.test.tsxindex 7e0cd62003..23b111afd5 100644--- a/packages/core/src/ComplexSelector/ComplexSelector.test.tsx+++ b/packages/core/src/ComplexSelector/ComplexSelector.test.tsx@@ -106,6 +106,31 @@ describe('ComplexSelector', () => {);});+ it('gives the popup clearance on both block edges, not just the leading one (#4803)', async () => {+ const user = userEvent.setup();+ render(+ <FruitComplexSelector+ value={{fruit: 'Apple', ripeness: 'Ripe'}}+ onChange={() => {}}+ />,+ );+ 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)');+ });+it('runs changeAction through the provided onChange helper', async () => {const user = userEvent.setup();const onChange = vi.fn();diff --git a/packages/core/src/ComplexSelector/ComplexSelector.tsx b/packages/core/src/ComplexSelector/ComplexSelector.tsxindex 35da221f63..3b2df8ff85 100644--- a/packages/core/src/ComplexSelector/ComplexSelector.tsx+++ b/packages/core/src/ComplexSelector/ComplexSelector.tsx@@ -119,7 +119,14 @@ 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',