Skip to content

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

TypeScript

fix(TopNav): stop clipping the focus ring inside expanded drawer sections (#7701)

홍규진a7d26b7c94b8
diff --git a/.changeset/topnav-drawer-focus-ring-clip.md b/.changeset/topnav-drawer-focus-ring-clip.md
new file mode 100644
index 0000000000..b881dc95ae
--- /dev/null
+++ b/.changeset/topnav-drawer-focus-ring-clip.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] An expanded `TopNavMenu` or `TopNavMegaMenu` section in the mobile drawer no longer clips the focus ring of its items. The section still clips while collapsed and while it animates open or closed.
+
+@kyu-rong
diff --git a/packages/core/src/TopNav/TopNavMegaMenu.test.tsx b/packages/core/src/TopNav/TopNavMegaMenu.test.tsx
index a4961743c4..e95aba4a9e 100644
--- a/packages/core/src/TopNav/TopNavMegaMenu.test.tsx
+++ b/packages/core/src/TopNav/TopNavMegaMenu.test.tsx
@@ -769,6 +769,28 @@ describe('TopNavMegaMenu — drawer mode', () => {
expect(handleClick).toHaveBeenCalledTimes(1);
});
+ it('clips the drawer section only while it is collapsed', async () => {
+ // The ring paints outside the item, so a permanent clip would cut it off.
+ const user = userEvent.setup();
+ render(
+ <TopNavRenderContext value="drawer">
+ <TopNavMegaMenu
+ label="Products"
+ items={<TopNavMegaMenuItem title="Analytics" href="/analytics" />}
+ />
+ </TopNavRenderContext>,
+ );
+ const trigger = screen.getByRole('button', {name: 'Products'});
+ const section = document.getElementById(
+ trigger.getAttribute('aria-controls') ?? '',
+ )!;
+ expect(getComputedStyle(section).overflow).toBe('hidden');
+ expect(getComputedStyle(section.firstElementChild!).overflow).toBe('');
+
+ await user.click(trigger);
+ expect(getComputedStyle(section).overflow).toBe('visible');
+ });
+
it('renders featured content when expanded', async () => {
const user = userEvent.setup();
diff --git a/packages/core/src/TopNav/TopNavMegaMenu.tsx b/packages/core/src/TopNav/TopNavMegaMenu.tsx
index e2308da7f1..d147cc3ab5 100644
--- a/packages/core/src/TopNav/TopNavMegaMenu.tsx
+++ b/packages/core/src/TopNav/TopNavMegaMenu.tsx
@@ -229,18 +229,22 @@ const styles = stylex.create({
drawerChevronExpanded: {
transform: 'rotate(180deg)',
},
+ // Clips only while collapsed or animating; see TopNavMenu drawerStyles.items.
drawerItems: {
display: 'grid',
gridTemplateRows: '0fr',
- transitionProperty: 'grid-template-rows',
- transitionDuration: durationVars['--duration-medium'],
+ overflow: 'hidden',
+ transitionProperty: 'grid-template-rows, overflow',
+ transitionBehavior: 'allow-discrete',
+ transitionDuration: `${durationVars['--duration-medium']}, 0s`,
transitionTimingFunction: easeVars['--ease-standard'],
},
drawerItemsExpanded: {
gridTemplateRows: '1fr',
+ overflow: 'visible',
+ transitionDelay: `0s, ${durationVars['--duration-medium']}`,
},
drawerItemsInner: {
- overflow: 'hidden',
minHeight: 0,
},
diff --git a/packages/core/src/TopNav/TopNavMenu.test.tsx b/packages/core/src/TopNav/TopNavMenu.test.tsx
index 7a87f89e72..0c86dbc4b9 100644
--- a/packages/core/src/TopNav/TopNavMenu.test.tsx
+++ b/packages/core/src/TopNav/TopNavMenu.test.tsx
@@ -241,6 +241,25 @@ describe('TopNavMenu — drawer focus ring', () => {
);
expectSharedFocusRing(screen.getByRole('link', {name: /Analytics/}));
});
+
+ it('clips the drawer section only while it is collapsed', async () => {
+ // The ring paints outside the item, so a permanent clip would cut it off.
+ const user = userEvent.setup();
+ render(
+ <TopNavRenderContext value="drawer">
+ <TopNavMenu label="Products" items={mockItems} />
+ </TopNavRenderContext>,
+ );
+ const trigger = screen.getByRole('button', {name: /Products/});
+ const section = document.getElementById(
+ trigger.getAttribute('aria-controls') ?? '',
+ )!;
+ expect(getComputedStyle(section).overflow).toBe('hidden');
+ expect(getComputedStyle(section.firstElementChild!).overflow).toBe('');
+
+ await user.click(trigger);
+ expect(getComputedStyle(section).overflow).toBe('visible');
+ });
});
describe('TopNavMenu pass-through props', () => {
diff --git a/packages/core/src/TopNav/TopNavMenu.tsx b/packages/core/src/TopNav/TopNavMenu.tsx
index 9a44336883..b3a54f6e8a 100644
--- a/packages/core/src/TopNav/TopNavMenu.tsx
+++ b/packages/core/src/TopNav/TopNavMenu.tsx
@@ -194,18 +194,26 @@ const drawerStyles = stylex.create({
chevronExpanded: {
transform: 'rotate(180deg)',
},
+ // The section clips its items only for the 0fr collapse animation: a
+ // permanent clip cuts off the focus ring, which paints outside the item.
+ // `overflow` is discrete, so it rides the transition with `allow-discrete`
+ // and switches to `visible` only after the open has finished. Collapsing
+ // clips again at once.
items: {
display: 'grid',
gridTemplateRows: '0fr',
- transitionProperty: 'grid-template-rows',
- transitionDuration: durationVars['--duration-medium'],
+ overflow: 'hidden',
+ transitionProperty: 'grid-template-rows, overflow',
+ transitionBehavior: 'allow-discrete',
+ transitionDuration: `${durationVars['--duration-medium']}, 0s`,
transitionTimingFunction: easeVars['--ease-standard'],
},
itemsExpanded: {
gridTemplateRows: '1fr',
+ overflow: 'visible',
+ transitionDelay: `0s, ${durationVars['--duration-medium']}`,
},
itemsInner: {
- overflow: 'hidden',
minHeight: 0,
},
item: {