Skip to content

CdsLayout

The frame of the application: CdsLayout places the header, the side drawers, the content and the footer, measures their sizes and takes the scrolling over. The parts of the layout know about each other — the content never slides under the header and never hides behind a drawer.

Storybook GitLab
Test coverage: 86% — partial coverage
API in specs
22 / 22 props, events, slots and exposed members with a test
Test cases
31 unit · 0 browser
Known bugs
1 pinned by an it.fails test
Code coverage
85.6% lines · 69% branches measured in v4.0.0-alpha.13
A11y (axe)
13 recommendations in 9 stories measured in v4.0.0-alpha.11

The parts of the layout are described on their own pages: CdsHeader, CdsDrawer, CdsMain, CdsPage, CdsFooter and CdsToolbar. You can assemble the frame with the mouse and copy the ready code in the layout builder.

Anatomy ​

CdsLayout is the root element of the application. The parts of the layout go inside it: the header, the drawers, CdsMain with CdsPage and the footer. The order in the template does not matter — the layout calculates the positions itself.

Variations ​

The view scheme ​

The view prop describes the layout with three strings: top, middle, bottom. The letters are the parts of the layout: h — the header, f — the footer, l and r — the left and the right drawer, p — the page. The corner letters of the top and the bottom string settle the argument over the corners: hhh gives the whole width to the header, lhh gives the top left corner to the drawer.

An uppercase letter gives the part position: fixed: HHH lpr fff nails the header to the window, hhh LPR fff nails both drawers. The default value is hhh lpr fff.

Container mode ​

By default the layout takes the whole page and controls its scrolling. The container prop locks it inside its parent: the layout gets its own scroll area, and the header and the footer keep their places inside it. This is a handy way to show the application in a preview, to embed it into somebody else's page or to build a working area of a fixed height.

Events ​

The layout watches its scroll area and shares what it sees: @scroll gives the position, the direction and the turning point, @resize gives the new sizes, @scroll-height gives the height of the content. The floating header and footer are built on these events, but you can use them for your own logic too — to load the next page of a list, for example.

Guidelines ​

Scenarios ​

Application shell ​

The typical set: a header with CdsToolbar, permanent navigation in CdsDrawer, CdsMain → CdsPage with the content and a footer. A button in the header toggles minified — the drawer shrinks to icons and gives the width to the content, and on hover it expands back.

A header that hides on scroll ​

On long lists the space is worth more than the navigation. The reveal prop of the header and the footer hides them when scrolling down and brings them back when scrolling up; reveal-offset sets the zone near the top of the list where the header stays in place.

Working area with filters ​

The lhh lpr fff scheme gives the top left corner to the navigation — it starts from the very top, and the header takes the remaining width. The right drawer with temporary slides over the content on a button click and closes on a click on the overlay, so it takes no place in the layout.

API ​

Props

NameTypeDefaultDescription
containerboolean | undefinedfalseContainer mode: the layout scrolls inside itself instead of scrolling the page.
themestring | undefined—Component theme
viewstring | undefined'hhh lpr fff'Layout scheme of three strings: top (header), middle (left-page-right), bottom (footer). For example 'hhh lpr fff'.

Events

NameTypeDescription
resize[contentRect: Pick<DOMRectReadOnly, "width" | "height">]The size of the layout area has changed.
scroll[info: ScrollObserver]The layout area has been scrolled.
scrollHeight[height: number]The height of the scrollable content has changed.

Slots

NameTypeDescription
defaultanyContent of the layout: CdsHeader, CdsDrawer, CdsMain, CdsFooter.

Exposed

NameTypeDescription
animate() => voidTurns on the rebuild animation of the layout for the duration of the next size update.
containerHeightnumberHeight of the content area without the header and the footer, in pixels.
footerLayoutPartSize and offset of the layout footer.
headerLayoutPartSize and offset of the layout header.
heightnumberFull height of the layout in pixels.
instancesRecord<string, unknown>Components registered in the layout by their identifiers — the header, the footer, the drawers, the content.
isContainerbooleanWhether the layout is limited in width by a container (container) instead of stretching across the whole screen.
leftLayoutPartSize and offset of the left drawer of the layout.
rightLayoutPartSize and offset of the right drawer of the layout.
rootRefHTMLElement | undefinedRef to the root DOM element of the layout.
rows{ top: string[]; middle: string[]; bottom: string[]; }Identifiers of the components distributed across the rows of the layout: top, middle and bottom.
scrollScrollObserverScroll state of the layout: position, direction and delta.
scrollbarWidthnumberWidth of the system scrollbar in pixels — taken into account when the scroll is locked.
totalWidthnumberFull width of the layout in pixels.
update(part: "left" | "right" | "footer" | "header", prop: keyof LayoutPart, value: number | boolean) => voidUpdates the size, the offset or the space reservation for a part of the layout.