The MenuItem component creates navigation menu items with support for icons, active states, nested children, and collapsible sections.
Usage
<script>
import { MenuItem } from '@invopop/popui'
import { Home } from '@invopop/ui-icons'
function handleClick(url) {
console.log('Navigate to:', url)
}
</script>
<MenuItem
label="Dashboard"
url="/dashboard"
icon={Home}
active={true}
onclick={handleClick}
/>
With Icon
<script>
import { MenuItem } from '@invopop/popui'
import { Settings } from '@invopop/ui-icons'
</script>
<MenuItem
label="Settings"
url="/settings"
icon={Settings}
iconTheme="solid"
onclick={(url) => console.log(url)}
/>
<script>
import { MenuItem } from '@invopop/popui'
import { FolderL } from '@invopop/ui-icons'
let open = $state(true)
const children = [
{ label: 'Invoices', url: '/documents/invoices', active: false },
{ label: 'Receipts', url: '/documents/receipts', active: false },
{ label: 'Reports', url: '/documents/reports', active: true }
]
</script>
<MenuItem
label="Documents"
icon={FolderL}
collapsable={true}
bind:open
{children}
onclick={(url) => console.log(url)}
/>
<script>
import { MenuItem } from '@invopop/popui'
import { Chart } from '@invopop/ui-icons'
const children = [
{ label: 'Overview', url: '/analytics/overview' },
{ label: 'Reports', url: '/analytics/reports' }
]
</script>
<MenuItem
label="Analytics"
url="/analytics"
icon={Chart}
collapsedSidebar={true}
{children}
onclick={(url) => console.log(url)}
/>
Beta Label
<script>
import { MenuItem } from '@invopop/popui'
import { Sparkles } from '@invopop/ui-icons'
</script>
<MenuItem
label="AI Assistant"
url="/ai"
icon={Sparkles}
beta={true}
onclick={(url) => console.log(url)}
/>
Props
The text label for the menu item
The URL to navigate to when clicked
Icon to display next to the label. Can be an IconSource from @steeze-ui/svelte-icon or a string path
iconTheme
'default' | 'solid' | 'mini'
default:"'default'"
The icon theme variant
Whether this menu item is currently active/selected
Whether the menu item can be collapsed to show/hide children
Controls the open/closed state of collapsable menu items. Use bind:open for two-way binding
When true, displays a compact version suitable for collapsed sidebars. Shows only the icon
Styles the item as a nested folder item with indentation and border
Shows a beta badge next to the label
Array of child menu items to display when expanded. Each child has the same props as MenuItem
Callback function when the menu item is clicked. Receives the URL as parameter
Behavior
- Active menu items are highlighted with a selected background
- When
collapsedSidebar is true and the item has children, hovering shows a floating context menu
- Clicking a collapsable item without a URL toggles the open/closed state
- Nested items (children) are automatically styled with indentation and connecting borders
- The component uses Svelte’s floating-ui for positioning hover menus in collapsed mode