Skip to content

Drawer w/ toolbar updates #2917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/brave-icons-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@leafygreen-ui/drawer': patch
---

- Updates `DrawerLayout` to accept the `disabled` property in `toolbarData` prop

```js
<DrawerLayout
toolbarData={[
{
...,
disabled: true, // This drawer item is disabled
},
]}
```
- Updates `DrawerLayout` to support `ReactNode` for the `title` property in `toolbarData` prop

```js
<DrawerLayout
toolbarData={[
{
...,
title: <span>Custom Title</span>, // This allows for custom React nodes as titles
},
]}
```
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ export const OverlaySwitchesToolbarItems: StoryObj<DrawerToolbarLayoutProps> = {

userEvent.click(dashboardButton!);

// Pause so the tooltip is in the correct position in the snapshot
await new Promise(resolve => setTimeout(resolve, 1000));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the waitFor ... element.toBeVisible not address this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not, can we use a less "magic" number than just 1000?

await waitFor(() => {
expect(canvas.getByText('Dashboard Title')).toBeVisible();
expect(getDrawer().textContent).toContain('Dashboard Title');
Expand Down Expand Up @@ -226,6 +229,9 @@ export const OverlayClosesDrawer: StoryObj<DrawerToolbarLayoutProps> = {

userEvent.click(closeButton);

// Pause so the tooltip is in the correct position in the snapshot
await new Promise(resolve => setTimeout(resolve, 1000));

await waitFor(() => expect(isOpen()).toBe(false));
},
};
Expand All @@ -246,6 +252,9 @@ export const EmbeddedOpensFirstToolbarItem: StoryObj<DrawerToolbarLayoutProps> =

userEvent.click(codeButton!);

// Pause so the tooltip is in the correct position in the snapshot
await new Promise(resolve => setTimeout(resolve, 1000));

await waitFor(() => {
expect(isOpen()).toBe(true);
expect(canvas.getByText('Code Title')).toBeVisible();
Expand Down Expand Up @@ -282,6 +291,9 @@ export const EmbeddedSwitchesToolbarItems: StoryObj<DrawerToolbarLayoutProps> =

userEvent.click(dashboardButton!);

// Pause so the tooltip is in the correct position in the snapshot
await new Promise(resolve => setTimeout(resolve, 1000));

await waitFor(() =>
expect(canvas.getByText('Dashboard Title')).toBeVisible(),
);
Expand Down Expand Up @@ -313,6 +325,9 @@ export const EmbeddedClosesDrawer: StoryObj<DrawerToolbarLayoutProps> = {

userEvent.click(closeButton!);

// Pause so the tooltip is in the correct position in the snapshot
await new Promise(resolve => setTimeout(resolve, 1000));

await waitFor(() => expect(isOpen()).toBe(false));
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ const DRAWER_TOOLBAR_DATA: DrawerLayoutProps['toolbarData'] = [
console.log('Plus clicked, does not update drawer');
},
},
{
id: 'Sparkle',
label: 'Disabled item',
glyph: 'Sparkle',
disabled: true,
},
];

const Component: StoryFn<DrawerLayoutProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DrawerProps } from '../Drawer/Drawer.types';
type PickedOptionalDrawerProps = Pick<DrawerProps, 'onClose' | 'displayMode'>;
type PickedRequiredToolbarIconButtonProps = Pick<
ToolbarIconButtonProps,
'glyph' | 'label' | 'onClick'
'glyph' | 'label' | 'onClick' | 'disabled'
>;

interface LayoutBase extends PickedRequiredToolbarIconButtonProps {
Expand All @@ -22,7 +22,7 @@ interface LayoutWithContent extends LayoutBase {
/**
* The title of the drawer. This is not required if the toolbar item should not open a drawer.
*/
title: string;
title: React.ReactNode;

/**
* The content of the drawer. This is not required if the toolbar item should not open a drawer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const DrawerToolbarLayoutContainer = forwardRef<
);
}}
active={toolbarItem.id === id}
disabled={toolbarItem.disabled}
/>
))}
</Toolbar>
Expand Down