Flyout Examples
The examples below assume that you have imported the components and set up the theme.
Basic
Open a popover from a trigger with markup only. The first element in the trigger slot toggles the flyout, and the default slot holds the content.
The control sets position-order, the position areas that the flyout tries first.
Shipping information
Orders normally arrive within three to five business days.
Express delivery can be picked at checkout.
<div class="flyout-basic"> <sv-flyout> <button type="button" class="trigger" slot="trigger">Shipping information</button>
<section class="panel" aria-labelledby="shipping-heading"> <h2 id="shipping-heading">Shipping information</h2> <p>Orders normally arrive within three to five business days.</p> <p>Express delivery can be picked at checkout.</p> </section> </sv-flyout></div>
<style> .flyout-basic { display: grid; justify-items: center;
.trigger { padding: 0.5em 0.75em; font: inherit; color: var(--sv-gray-1); cursor: pointer; background-color: var(--sv-gray-6); border: solid var(--sv-bdr-sz-sm) var(--sv-gray-5); border-radius: var(--sv-bdr-rad-md); }
.panel { max-inline-size: 16rem; padding: 0.25em;
h2 { margin: 0; font-size: 1rem; color: var(--sv-gray-1); }
p { margin: 0.5em 0 0; font-size: 0.875rem; line-height: 1.5; color: var(--sv-gray-2); } } }</style>Custom States
Style the trigger or nearby elements by the flyout's open state. :state(--opened), :state(--opening), and :state(--closing) match the flyout, and --opened starts together with the opening animation.
Watch the label above the trigger. It names the state the flyout is in right now.
--opened--opening--closing
<div class="flyout-custom-states"> <sv-flyout> <button type="button" class="trigger" slot="trigger"> Filters
<!-- Chevron --> <svg class="chevron" aria-hidden="true" viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg" > <path d="M480-360 280-560h400L480-360Z"></path> </svg> </button>
<p class="panel"> Watch the label above the trigger. It names the state the flyout is in right now. </p> </sv-flyout>
<span class="state-label">state:</span></div>
<style> .flyout-custom-states { display: grid; gap: 0.75em; justify-items: center;
.trigger { display: flex; gap: 0.5em; align-items: center; padding: 0.5em 0.75em; font: inherit; color: var(--sv-gray-1); cursor: pointer; background-color: var(--sv-gray-6); border: solid var(--sv-bdr-sz-sm) var(--sv-gray-5); border-radius: var(--sv-bdr-rad-md); transition: border-color 200ms ease; }
.chevron { inline-size: 1.1em; block-size: 1.1em; fill: currentcolor; transition: rotate 200ms ease; }
sv-flyout:state(--opened) { .trigger { border-color: var(--sv-accent); }
.chevron { rotate: 180deg; } }
.panel { max-inline-size: 11rem; margin: 0; font-size: 0.875rem; line-height: 1.4; color: var(--sv-gray-2); }
.state-label { /* Rendered above the trigger while staying after the flyout in the DOM, where the sibling selectors below can reach it */ order: -1; font-size: 0.8em; color: var(--sv-gray-3);
&::after { content: " closed"; } }
sv-flyout:state(--opened) + .state-label::after { content: " open"; }
sv-flyout:state(--opening) + .state-label::after { content: " opening"; }
sv-flyout:state(--closing) + .state-label::after { content: " closing"; }
@media (prefers-reduced-motion: reduce) { .trigger, .chevron { transition: none; } } }</style>