An open source design system that's fully customizable and agent ready
TypeScript
fix(Dialog): reset inherited edge signals to prevent ghost button margin shift (#1237)
Andrey Goder86b291140b58
diff --git a/packages/core/src/Dialog/XDSDialog.test.tsx b/packages/core/src/Dialog/XDSDialog.test.tsxindex b29ced6efb..3a4f9b406a 100644--- a/packages/core/src/Dialog/XDSDialog.test.tsx+++ b/packages/core/src/Dialog/XDSDialog.test.tsx@@ -277,4 +277,39 @@ describe('XDSDialog', () => {expect(wrapper.parentElement!.tagName).toBe('DIALOG');});});++ describe('edge signal isolation', () => {+ it('resets inherited --edge-end from ancestor containers', () => {+ // Simulate the bug: Dialog rendered inside TopNav's endContent+ // which sets --edge-end: 1 via edgeSignals.end+ render(+ <div style={{'--edge-end': '1'} as React.CSSProperties}>+ <XDSDialog isOpen={true} onOpenChange={() => {}}>+ <div data-testid="child">Content</div>+ </XDSDialog>+ </div>,+ );++ const dialog = screen.getByRole('dialog');+ // The dialog element should have isolateEdgeSignals styles applied,+ // resetting --edge-start and --edge-end to 0 so ghost buttons inside+ // (like the close button) don't apply unwanted edge compensation+ expect(dialog).toBeInTheDocument();+ expect(dialog.getAttribute('class')).toBeTruthy();+ });++ it('resets inherited --edge-start from ancestor containers', () => {+ render(+ <div style={{'--edge-start': '1'} as React.CSSProperties}>+ <XDSDialog isOpen={true} onOpenChange={() => {}}>+ <div data-testid="child">Content</div>+ </XDSDialog>+ </div>,+ );++ const dialog = screen.getByRole('dialog');+ expect(dialog).toBeInTheDocument();+ expect(dialog.getAttribute('class')).toBeTruthy();+ });+ });});diff --git a/packages/core/src/Dialog/XDSDialog.tsx b/packages/core/src/Dialog/XDSDialog.tsxindex 88ab4cb6d1..7e046a035e 100644--- a/packages/core/src/Dialog/XDSDialog.tsx+++ b/packages/core/src/Dialog/XDSDialog.tsx@@ -157,6 +157,14 @@ const styles = stylex.create({margin: 0,inset: 0,},+ // Reset inherited edge signals so that dialogs rendered as DOM descendants+ // of containers (e.g. TopNav endContent) don't inherit --edge-start/--edge-end.+ // CSS custom properties inherit through the DOM tree even for top-layer elements,+ // causing ghost buttons (like the close button) to apply unwanted edge compensation.+ isolateEdgeSignals: {+ '--edge-start': '0',+ '--edge-end': '0',+ },inner: {display: 'flex',flexDirection: 'column',@@ -424,6 +432,7 @@ export function XDSDialog({stylex.props(styles.dialog,styles.backdrop,+ styles.isolateEdgeSignals,!isFullscreen && dynamicStyles.sizing(width, maxHeight),hasPosition &&dynamicStyles.position(