Skip to content

toggle

toggle is a DOM event that occurs whenever the menu view is being toggled.

Event body

The toggle body has a TMenuToggleEventDetail type which represents the details of the toggled menu element. It is optional so it might not exist.

Example

In this example we listen to toggle event and perform an action whenever it's emitted.

useStorefront(async (storefront) => {
    document.addEventListener('toggle', (event) => {
        const $menuElement = event.detail?.$el;

        console.log('This menu is being toggled:', $menuElement);
    });
});