Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Primitives
  2. Contents
  3. Usage

Contents

Usage

Contents renders an element that takes no part in layout: a div with display: contents. Its children are laid out by the nearest box-generating ancestor, as if Contents were not there. Use it only when an element must exist in the DOM without changing layout.
When to use Contents
NeedUse
A ref to observe, measure or portal into, around children that a parent FlexBox or Grid must still lay outContents with ref
A data-* hook (a test id, a tracking label, a mount marker) around children that the parent must still lay outContents with data-*
Group children with no element at allA fragment
Children need gap, padding, alignment, size or paintBox, FlexBox or Grid with props
One child that is already a Box, FlexBox or GridPut the ref and data-* on that child
Semantics: a list, a landmark, a heading, a labelled groupA Box with as, or the shipped component
The remote's children become flex items of the FlexBox, and its gap applies between them.
What Contents does not take
Contents accepts children, ref and data-* attributes, nothing else. There is no className, style, regionClass, as, Box layout prop, role, aria-*, id, tabIndex or event handler. Each is declared never, so passing one is a type error even through a spread. Contents generates no box, so there is nothing to lay out or paint; regionClass stays on Box and FlexBox.
Lint
design-system/contents-layout-transparent fails when Contents:
  • gets any attribute other than children, key, ref or data-*, or a spread;
  • has neither a ref nor a data-* attribute (use a fragment);
  • wraps a single Box, FlexBox, Grid or Contents (put the ref and data-* on that element).
Previous
Collapsible / Accessibility
Next
Contents / API and Development
On this page
When to use Contents
What Contents does not take
Lint