Flyout
A non-modal overlay, showing contextually relevant content.
Flyout overlays with pointers

Introduction

Flyout is a composite pattern containing an element that hosts a non-modal overlay. The overlay typically discloses secondary or tertiary content related to the host element.
Flyout forms the basis of the following composite patterns:
The pattern discussed here is the more generic use-case, where the flyout overlay may contain some other kind of content than listed above.
Updated: May 9th, 2019

Working Examples

You can take a look at a generic flyout on our examples site.

Terminology

    flyout: the composite pattern as a *whole*, containing an overlay and it's host
    host: the element that hosts the overlay
    overlay: the non-modal overlay that contains the content related to it's host
    content: the actual content of the overlay
    expanded/collapsed: the overlay state (visible or hidden)

Best Practices

The overlay can hold any kind of content, but for an overlay that demands user acknowledgement or input, or with additional rich interactions, consider using a dialog instead.
The overlay expands or collapses via any combination of the following events:
    Click event of host
    Hover event of host
    Focus event of host
    System event at page load or after some arbitrary time
A link must not be the host of a click-activated flyout. Clicking the host should always navigate to the URL in this case.
Overlay must be non-modal (i.e. must not trap keyboard focus or mask page background). For modal behaviour please consider the dialog pattern instead.
Overlay must be placed directly after the host in DOM. This ensures natural tab order and reading order without JavaScript.
If system-activated, overlay must remain onscreen until explicitly dismissed by the user,
If focus-activated, overlay should not contain long blocks of interactive elements. This measure prevents keyboard users from having to tab through secondary or tertiary content inside of the overlay.

Interaction Design

This section provides interaction guidelines for keyboard, screen reader, and pointing devices.

Keyboard

Tab order must flow directly from host into first focusable element inside overlay. If the overlay has no focusable element, tab order flows to next page control instead.
If not system-activated, host must be keyboard focus-able.
If focus-activated, flyout must expand when host receives keyboard focus.
If focus-activated, flyout must collapse when flyout loses keyboard focus.
If click-activated, flyout must expand overlay when host receives keyboard click.

Screen Reader

Reading order must flow directly from host into overlay.
If system-activated and high-priority, screen reader must announce presence and/or content overlay.

Mouse

If hover-activated, flyout must expand when host receives mouse hover.
If click-activated, flyout must expand when host receives mouse click.
If system-activated, flyout must collapse when clicking close button.

Touch

Hover behaviour can be problematic or impossible for touch. You may wish to consider using the Bubble Help pattern instead.
If click-activated, flyout must expand when host receives tap.
if system-activated, flyout must close when tapping close button.

Developer Guide

Let's examine a click-activated flyout. Click-activated flyouts typically occur with buttons, where clicking the button expands the flyout.
The key things to consider are:
    1.
    Server-side rendering or client-side rendering of overlay content (or both)
    2.
    Placement of overlay element in relation to host
    3.
    Using aria-expanded state to toggle CSS display
    4.
    Determining the live-region property

Content

Content rendered by the server will be visible by default before & without CSS or JavaScript. If the content is secondary in nature, you may wish to render the content on the client instead.
Whatever progressive enhancement strategy you choose, the following structure is the goal:
1
<span class="flyout flyout--click">
2
<button class="flyout__host" type="button" disabled>Toggle Flyout</button>
3
<span aria-live="off">
4
<div class="flyout__overlay">
5
<!-- flyout content -->
6
</div>
7
</span>
8
</span>
Copied!
Notice placement of the host (the button) directly before the overlay element. This allows natural keyboard and reading order from the host into the overlay.
An optional live-region element wraps the overlay. The live-region property may be set to "off", "polite" or "assertive".

Presentation

The overlay can be absolute or fixed positioned:
1
.flyout__overlay {
2
display: none;
3
position: absolute;
4
z-index: 1;
5
}
Copied!
We have hidden the overlay by default (display: none). We use the aria-expanded state of the host to control the display of the overlay:
1
.flyout__host[aria-expanded=true] ~ [aria-live] .flyout__overlay {
2
display: block;
3
}
Copied!

Behaviour

CSS alone cannot trigger the expanded state, so we require a small amount of Javascript to handle this behaviour:
1
document.querySelector('.flyout__host').addEventListener('click', function() {
2
const isExpanded = this.getAttribute('aria-expanded') === 'true';
3
4
this.setAttribute('aria-expanded', isExpanded ? 'false' : 'true');
5
});
Copied!
Clicking the button with mouse, keyboard or touch will now toggle the aria-expanded state of the button.

ARIA Reference

aria-expanded

This boolean attribute signifies the expanded state of the host element.

aria-live

To announce overlay content when flyout expands use a value of "polite".
Last modified 11mo ago