Skip to content

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

TypeScript

fix(Toolbar): stop the center slot from clipping its content (#6898)

Kenton Quatman490970c7a8c2
diff --git a/.changeset/toolbar-center-slot-unclipped.md b/.changeset/toolbar-center-slot-unclipped.md
new file mode 100644
index 0000000000..fd1d87d52d
--- /dev/null
+++ b/.changeset/toolbar-center-slot-unclipped.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Toolbar's center slot no longer clips its content, so focus rings, box-shadows, and the selected-tab indicator of a TabList in `centerContent` are drawn in full. Center content that cannot shrink and is wider than the space between the start and end slots now overflows it instead of being cut off.
+@kentonquatman
diff --git a/apps/storybook/stories/Toolbar.stories.tsx b/apps/storybook/stories/Toolbar.stories.tsx
index 8c9119ed76..d7a27e6c7c 100644
--- a/apps/storybook/stories/Toolbar.stories.tsx
+++ b/apps/storybook/stories/Toolbar.stories.tsx
@@ -444,3 +444,45 @@ export const WithTabNavigation: Story = {
);
},
};
+
+/**
+ * Tabs in the center slot of a divided toolbar. The selected-tab indicator
+ * sits on the divider rail, just outside the slot's box, so the slot must not
+ * clip its content (the same goes for box-shadows and focus rings).
+ */
+export const WithCenterTabNavigation: Story = {
+ name: 'Composition: Center Tab Navigation',
+ render: () => {
+ const [tab, setTab] = useState('overview');
+ return (
+ <Card>
+ <Toolbar
+ label="Center tab navigation"
+ dividers={['bottom']}
+ startContent={
+ <Button
+ label="Back"
+ variant="ghost"
+ icon={<ArrowLeftIcon style={{width: 16, height: 16}} />}
+ isIconOnly
+ />
+ }
+ centerContent={
+ <TabList
+ value={tab}
+ onChange={setTab}
+ aria-label="Center tab navigation">
+ <Tab value="overview" label="Overview" />
+ <Tab value="analytics" label="Analytics" />
+ <Tab value="settings" label="Settings" />
+ </TabList>
+ }
+ endContent={<Button label="New item" />}
+ />
+ <Section>
+ <Text type="body">Content for the center tab navigation</Text>
+ </Section>
+ </Card>
+ );
+ },
+};
diff --git a/docs/pr-assets/6898/center-tabs-after.png b/docs/pr-assets/6898/center-tabs-after.png
new file mode 100644
index 0000000000..52715a41a7
Binary files /dev/null and b/docs/pr-assets/6898/center-tabs-after.png differ
diff --git a/docs/pr-assets/6898/center-tabs-before.png b/docs/pr-assets/6898/center-tabs-before.png
new file mode 100644
index 0000000000..2869d5c335
Binary files /dev/null and b/docs/pr-assets/6898/center-tabs-before.png differ
diff --git a/docs/pr-assets/6898/focus-ring-after.png b/docs/pr-assets/6898/focus-ring-after.png
new file mode 100644
index 0000000000..ef65d859fe
Binary files /dev/null and b/docs/pr-assets/6898/focus-ring-after.png differ
diff --git a/docs/pr-assets/6898/focus-ring-before.png b/docs/pr-assets/6898/focus-ring-before.png
new file mode 100644
index 0000000000..5b056a4e02
Binary files /dev/null and b/docs/pr-assets/6898/focus-ring-before.png differ
diff --git a/docs/pr-assets/6898/shadow-after.png b/docs/pr-assets/6898/shadow-after.png
new file mode 100644
index 0000000000..f46dd5e6db
Binary files /dev/null and b/docs/pr-assets/6898/shadow-after.png differ
diff --git a/docs/pr-assets/6898/shadow-before.png b/docs/pr-assets/6898/shadow-before.png
new file mode 100644
index 0000000000..bbdcfae1a9
Binary files /dev/null and b/docs/pr-assets/6898/shadow-before.png differ
diff --git a/docs/pr-assets/6898/squeezed-after.png b/docs/pr-assets/6898/squeezed-after.png
new file mode 100644
index 0000000000..eacecc36fc
Binary files /dev/null and b/docs/pr-assets/6898/squeezed-after.png differ
diff --git a/docs/pr-assets/6898/squeezed-before.png b/docs/pr-assets/6898/squeezed-before.png
new file mode 100644
index 0000000000..6197ea4043
Binary files /dev/null and b/docs/pr-assets/6898/squeezed-before.png differ
diff --git a/packages/core/src/Toolbar/Toolbar.test.tsx b/packages/core/src/Toolbar/Toolbar.test.tsx
index 4636a66b63..c8ac8ae56c 100644
--- a/packages/core/src/Toolbar/Toolbar.test.tsx
+++ b/packages/core/src/Toolbar/Toolbar.test.tsx
@@ -181,6 +181,66 @@ describe('Toolbar', () => {
expect(sectionInner).toHaveAttribute('data-variant', 'transparent');
});
+ describe('slot clipping', () => {
+ // The slot wrappers are the direct parents of the caller's content. A slot
+ // that clips its overflow cuts off anything its children paint outside
+ // their own box (box-shadow, focus rings, hover halos).
+ function slotOf(testId: string): HTMLElement {
+ const slot = screen.getByTestId(testId).parentElement;
+ if (slot == null) {
+ throw new Error(`expected "${testId}" to sit inside a slot`);
+ }
+ return slot;
+ }
+
+ function clipsOverflow(el: HTMLElement): boolean {
+ const style = getComputedStyle(el);
+ return [style.overflow, style.overflowX, style.overflowY].some(value =>
+ ['hidden', 'clip', 'auto', 'scroll'].includes(value),
+ );
+ }
+
+ it('does not clip any slot in the three-slot layout', () => {
+ render(
+ <Toolbar
+ label="Actions"
+ startContent={<span data-testid="start">Start</span>}
+ centerContent={<span data-testid="center">Center</span>}
+ endContent={<span data-testid="end">End</span>}
+ />,
+ );
+ expect(clipsOverflow(slotOf('start'))).toBe(false);
+ expect(clipsOverflow(slotOf('center'))).toBe(false);
+ expect(clipsOverflow(slotOf('end'))).toBe(false);
+ });
+
+ it('does not clip any slot in the two-slot layout', () => {
+ render(
+ <Toolbar
+ label="Actions"
+ startContent={<span data-testid="start">Start</span>}
+ endContent={<span data-testid="end">End</span>}
+ />,
+ );
+ expect(clipsOverflow(slotOf('start'))).toBe(false);
+ expect(clipsOverflow(slotOf('end'))).toBe(false);
+ });
+
+ it('still lets the center slot shrink below its content width', () => {
+ render(
+ <Toolbar
+ label="Actions"
+ startContent={<span data-testid="start">Start</span>}
+ centerContent={<span data-testid="center">Center</span>}
+ endContent={<span data-testid="end">End</span>}
+ />,
+ );
+ // The `auto` track only shrinks for an item whose minimum width is zero.
+ // Dropping the clip must not turn a narrow toolbar into a wider one.
+ expect(parseFloat(getComputedStyle(slotOf('center')).minWidth)).toBe(0);
+ });
+ });
+
it('navigates with ArrowRight/ArrowLeft in horizontal orientation', async () => {
const user = userEvent.setup();
render(
diff --git a/packages/core/src/Toolbar/Toolbar.tsx b/packages/core/src/Toolbar/Toolbar.tsx
index d447f0bb1e..5cd21a49f4 100644
--- a/packages/core/src/Toolbar/Toolbar.tsx
+++ b/packages/core/src/Toolbar/Toolbar.tsx
@@ -71,12 +71,15 @@ const styles = stylex.create({
display: 'flex',
alignItems: 'center',
},
+ // `minWidth: 0` lets the `auto` track shrink below the content's width, so a
+ // wide center never widens the toolbar. The slot deliberately does not clip
+ // (`overflow`): clipping would cut off the box-shadow and focus ring of its
+ // outermost children, which paint outside their own box.
centerSlot: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
minWidth: 0,
- overflow: 'hidden',
},
endSlot: {
display: 'flex',