opened¶
opened
is a DOM event that occurs whenever the menu has been opened.
Event body¶
The opened
body has a { currentView: View<TMenuViewData> | undefined }
type where View
represents the View model and TMenuViewData
represents the TMenuViewData object which represents the details of the selected item. It is optional so it might not exist.
Example¶
In this example we listen to opened
event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
document.addEventListener('opened', (event) => {
const menuViewData = event.detail;
if (!menuViewData) return;
const { currentView } = menuViewData;
console.log('A menu view has been opened with id:', currentView.id, ' and following data: ', currentView.data);
});
});