Skip to main content

On Click

The onClick prop allows you to define a custom function that will be called when the menu item is clicked. It provides a way to handle the click event and perform specific actions or logic in response to the click.

Props

onClick?: (event: React.MouseEvent<HTMLElement>) => void

Example

/vertical-menu/menu-item/on-click

Click on Analytics and check console

Source Code

'use client'

// Component Imports
import VerticalNav, { Menu, MenuItem } from '@menu/vertical-menu'

const OnClick = () => {
return (
<div className='flex'>
<VerticalNav customBreakpoint='200px'>
<Menu>
<MenuItem
onClick={() => {
console.log('Analytics Dashboard clicked')
}}
>
Analytics Dashboard
</MenuItem>
<MenuItem>Calendar</MenuItem>
<MenuItem>FAQ</MenuItem>
<MenuItem>Form Layout</MenuItem>
<MenuItem>Documentation</MenuItem>
</Menu>
</VerticalNav>
<main className='p-4 flex-grow'>
<p>Click on Analytics and check console</p>
</main>
</div>
)
}

export default OnClick