Search
HomeGet startedDevelopStylesComponents
Develop index

Scaffold

PublishedUpdated

The scaffold is a frame for a screen, or for any part of one. It always has a pane, the content; everything else is optional: a second pane beside the first, bars at the top and bottom, rails at the sides. It arranges them by the space it is given, following its own box and not the window, so a whole app's page can be one, and so can a card, a dialog's content or a phone-sized preview.

The scaffold is a preview in 3.17.0: it is in material@next from 3.17.0-next.4 (its single pane and its widths from 3.17.0-next.7), and its names and options may still change before 3.17.0. It is opt-in: nothing in material, material/styles or material/elements includes it, so each use imports its own entry and its own stylesheet.

Use it

import createScaffold from 'material/components/scaffold';
import 'material/styles/base';
import 'material/styles/scaffold';

const list = document.createElement('div');
list.textContent = 'Messages';
const detail = document.createElement('article');
detail.textContent = 'The message';

const scaffold = createScaffold({
  layout: 'list-detail',
  panes: { list, detail },
  labels: { list: 'Messages', detail: 'Message' },
});
document.body.append(scaffold.element);

The scaffold fills the height of the box it is in, so give that box one: height: 100dvh on the page's root, for example. Each pane scrolls on its own.

A small one

A scaffold in a box of 360 by 420px: the bars keep their places and the list between them scrolls.

<div class="preview">
  <m-scaffold layout="single-pane" main-label="Inbox">
    <m-app-bar slot="top" headline="Inbox" no-scroll></m-app-bar>
    <m-list slot="main" aria-label="Mail" selection="none">
      <m-list-item headline="Ada Vale" supporting-text="Lunch on Friday?"></m-list-item>
      <m-list-item headline="Sam Holt" supporting-text="The train tickets"></m-list-item>
    </m-list>
    <m-navigation-bar slot="bottom" value="mail">
      <m-navigation-bar-item value="mail" icon="…">Mail</m-navigation-bar-item>
      <m-navigation-bar-item value="chat" icon="…">Chat</m-navigation-bar-item>
    </m-navigation-bar>
  </m-scaffold>
</div>
.preview {
  width: 360px;
  height: 420px;
  overflow: hidden;
}

A single pane has no role and no name unless main-label gives one. For content that goes edge to edge, set --mtrl-scaffold-margin-leading and --mtrl-scaffold-margin-trailing to 0px on the element.

Layouts

Layout Panes On a wide frame
list-detail (default) list, detail The list is the fixed pane, at the leading side
supporting-pane main, supporting The supporting pane is the fixed pane, at the trailing side
feed feed One pane at every width, named "Feed"
single-pane main One pane at every width, with no name of its own

The default is list-detail, which keeps a place for both its panes: for one pane, say single-pane.

supportingPosition: 'leading' (supporting-position="leading" on the element) puts the supporting pane first, on screen and in the document. setSupportingPosition(side) moves it later, in supporting-pane only.

By width

The scaffold measures its own width, not the window's, so one inside a dialog or a split view follows its box.

Width Size class Margins Panes
under 600px compact 16px The selected one; the side regions are hidden
from 600px medium 24px The selected one
from 840px expanded 24px Two: the fixed one is 360px
from 1200px large (extra-large from 1600px) 24px Two: the fixed one is 412px

Two options change when and how two panes show, in whole pixels: twoPaneMinWidth (two-pane-min-width) is the width from which they may, in place of 840px, and fixedPaneWidth (fixed-pane-width) is the fixed pane's. This one has both panes in a box of 600px:

<m-scaffold two-pane-min-width="600" fixed-pane-width="200" list-label="Messages" detail-label="Message">
  <div slot="list">Messages</div>
  <article slot="detail">The message</article>
</m-scaffold>

The panes are 24px apart. A second pane shows only when the other keeps at least 320px: a rail that takes too much leaves the selected pane alone. getSize() and getVisible() answer for now; sizechange tells of a new size class.

Show a pane

When one pane fits, the selected one shows. show(pane) asks first, through panerequest, then selects the pane and reports it with panechange; it answers whether the pane changed. dismiss() shows the layout's first pane the same way: a back button calls it. Prevent the request to keep the pane, while a draft is unsaved for instance.

let unsaved = false;
scaffold.on('panerequest', (request) => {
  if (unsaved) request.preventDefault();
});
scaffold.on('panechange', ({ pane, visible }) => {
  console.log(pane, visible);
});

scaffold.show('detail');
scaffold.dismiss();

An empty pane is never shown, nor one the layout does not have. setPane(pane) writes the selection with no request and no event, for a value the app already decided, such as the address.

When the pane that holds focus goes, focus moves to the pane now selected. Nothing else moves it.

Regions

top, bottom, leading and trailing hold bars and rails: options in the factory, slots on the element. An app bar in top stands above the panes, not over them. leading and trailing are hidden under 600px, where a navigation bar goes in bottom instead. The scaffold does not switch between the two by itself in this preview.

const toolbar = document.createElement('div');
toolbar.textContent = 'Inbox';

scaffold.setRegion('top', toolbar);
scaffold.setRegion('top', null);

The web component

The web component is <m-scaffold>. Its entry registers it, and its stylesheet has an entry of its own:

import 'material/elements/css/scaffold';
import { defineScaffold } from 'material/components/scaffold/element';

defineScaffold();
<m-scaffold layout="list-detail" list-label="Messages" detail-label="Message">
  <m-app-bar slot="top" headline="Inbox"></m-app-bar>
  <div slot="list">Messages</div>
  <article slot="detail">The message</article>
</m-scaffold>

In a framework

Each framework has an entry of its own, which brings the element's stylesheet. Panes and regions are slots; defaultPane sets the first pane. A ref to the element has show() and dismiss(). An app that keeps the pane in its state binds pane, and in panerequest prevents the request and sets its state.

import { useRef } from 'react';
import { Scaffold } from 'material/react/scaffold';
import type { ScaffoldElement } from 'material/components/scaffold/element';

export function Mail() {
  const scaffold = useRef<ScaffoldElement>(null);
  return (
    <Scaffold
      ref={scaffold}
      layout="list-detail"
      defaultPane="list"
      list={<button onClick={() => scaffold.current?.show('detail')}>Budget review</button>}
      detail={<button onClick={() => scaffold.current?.dismiss()}>Back to the list</button>}
    />
  );
}
<script setup lang="ts">
import { MScaffold } from 'material/vue/scaffold';
</script>

<template>
  <MScaffold layout="list-detail" default-pane="list">
    <template #list>Messages</template>
    <template #detail>The message</template>
  </MScaffold>
</template>
<script lang="ts">
  import Scaffold from 'material/svelte/scaffold';
</script>

<Scaffold layout="list-detail" defaultPane="list">
  {#snippet list()}Messages{/snippet}
  {#snippet detail()}The message{/snippet}
</Scaffold>
import { Scaffold } from 'material/solid/scaffold';

export const Mail = () => (
  <Scaffold
    layout="list-detail"
    defaultPane="list"
    list={<p>Messages</p>}
    detail={<article>The message</article>}
  />
);

On the server

material/components/scaffold/server renders the element with its declarative shadow root and its stylesheet inline, so it has its layout before any script. The element keeps that tree as it upgrades: the panes' scroll, the focus and typed text stay.

import { renderScaffold } from 'material/components/scaffold/server';

const html = renderScaffold(
  { layout: 'list-detail', 'list-label': 'Messages', 'detail-label': 'Message' },
  '<div slot="list">Messages</div><article slot="detail">The message</article>',
);

With a framework's server rendering, import that entry in the server process as well as the framework's bridge (Server rendering). The second argument goes through your markup policy; without one it is written as it is, so escape what users wrote.

Configuration

Option Attribute Type Default
layout layout list-detail, supporting-pane, feed, single-pane list-detail
twoPaneMinWidth two-pane-min-width Whole pixels, from 1 to 10000 840
fixedPaneWidth fixed-pane-width Whole pixels, from 1 to 10000 360, or 412 from 1200px
pane pane A pane of the layout The layout's first pane
supportingPosition supporting-position leading, trailing trailing
labels list-label, detail-label, main-label, supporting-label, feed-label string The pane's name
panes slots list, detail, main, supporting, feed HTMLElement each
top, bottom, leading, trailing slots of the same names HTMLElement
container HTMLElement the scaffold is appended to

Accessibility

Each pane is a group with a name for assistive technology: its own ("List", "Detail") unless labels gives one. A single pane is neither, unless labels names it. Give the names your users know. The document's order is the order on screen.