Skip to content

select

select is a DOM event that occurs whenever the variant option is selected.

Event body

The select body has a VariantStockOptionValue or VariantVirtualOptionValue type depending on an option type which represents the details of the selected option. It is optional so it might not exist.

Example

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

useStorefront(async (storefront) => {
    document.addEventListener('select', (event) => {
        const option = event.detail;

        console.log('selected option:', option);
    });
});