A fully accessible, animated drawer component for React with nested navigation support, smooth transitions, and keyboard shortcuts.
Note
Deployed : https://nested-drawer.milind.app
- Direction-aware navigation with smooth slide animations
- Automatic height transitions between menu levels
- Keyboard accessible (Tab, Escape, Cmd/Ctrl+K)
- Compound component pattern for flexible composition
- TypeScript support
- Built with Framer Motion and Tailwind CSS
import { NestedDrawer, TMenuItem } from "@/components/nested-drawer";
const menuData: TMenuItem[] = [
{
id: "home",
title: "Home",
description: "Go to homepage",
icon: <HomeIcon />,
onClick: () => console.log("Home clicked"),
},
{
id: "products",
title: "Products",
description: "Browse products",
icon: <PackageIcon />,
children: [
{
id: "software",
title: "Software",
icon: <ServerIcon />,
onClick: () => console.log("Software clicked"),
},
],
},
];
function App() {
return (
<NestedDrawer initialMenu={menuData}>
<NestedDrawer.Trigger>Open Menu</NestedDrawer.Trigger>
<NestedDrawer.Content title="Main Menu">
<NestedDrawer.Menu />
</NestedDrawer.Content>
</NestedDrawer>
);
}Main container component.
initialMenu: Array of menu items to displaychildren: Compound components (Trigger, Content)
type TMenuItem = {
id: string; // Unique identifier
title: string; // Display text
description?: string; // Optional subtitle
icon?: React.ReactNode; // Optional icon
children?: TMenuItem[]; // Nested menu items
onClick?: () => void; // Action when clicked (leaf items)
};NestedDrawer.Trigger: Button to open the drawerNestedDrawer.Content: Drawer overlay and containerNestedDrawer.Menu: Renders the current menu level
Cmd+KorCtrl+K: Open drawerEscape: Go back one level or close drawerTab/Shift+Tab: Navigate between itemsEnter/Space: Select item