Skip to Content
πŸŽ‰ Coral x Panda has been released πŸŽ‰ Read the Migration Guide

GridSubgrid

GridSubgrid is a component that is a combination of props available on Grid and GridItem, allowing your nested grid to align with the parent grid’s tracks, rather than creating its own independent tracks.

All docs for GridSubgrid will use a Grid component as a parent. This is to ensure that the GridSubgrid is rendered correctly.

There is comprehensive documentation available for subgrids available on MDN Web DocsΒ , but in brief: you can β€œnest” grids by making a grid item a grid container. This grid, however, would be independent of the parent grid and of any other grid items, meaning that it would not take its track sizing from the parent grid. This makes it difficult to line nested grid items up with the main grid. If you set the value subgrid on grid-template-columns, grid-template-rows or both, however, instead of creating a new track listing, the nested grid uses the tracks defined on the parent.

Basic Usage

This example tracks the example from the MDN Web Docs on SubgridΒ . The grid layout has nine 1fr column tracks and four rows.

GridSubgrid is placed between column lines 2 to 7 and rows 2 to 4. This item is itself specified as a grid and then defined as a subgrid by giving it column tracks that are a subgrid (gridTemplateColumns="subgrid") and normally defined rows. The subgrid has five-column tracks as it spans five column tracks.

Because this is a subgrid, even though the GridItem is not a direct child of the outer Grid, it can be placed on that outer grid, with its columns aligned with the outer grid’s columns. The rows are not a subgrid, so behave as a nested grid normally does. The grid area on the parent expands to be large enough for this nested grid.

Note that the example uses custom styling to make the grid and items visible.

<Grid gridTemplateRows="repeat(4, minmax(100px, auto))" gridTemplateColumns="repeat(9, 1fr)" > <GridSubgrid gridColumn="2 / 7" gridRow="2 / 4" gridTemplateColumns="subgrid" gridTemplateRows="repeat(3, 80px)" gap="none" > <GridItem gridColumn="3 / 6" gridRow="1 / 3"></GridItem> </GridSubgrid> </Grid>

Full API

NameTypeDefault
childrenReactNode
attributesAttributes

This prop can be used to pass HTML attributes directly to the component. We currently allow passing data-* and aria-* attributes and the id. However, you can pass anything else with a type hack if necessary since this object is despread in to the component, without filtering its content.

Example usage:

AttributesProps: { 'id': 'close-button', 'aria-label': 'Close button', 'data-testid': 'close-button' };
gridColumnResponsiveVariant<`span ${string}` | `span ${number}` | "auto" | `${number} / span ${string}` | `${number} / span ${number}` | `${number} / ${number}`>

The column number the grid item should span.

gridColumnStartResponsiveVariant<number | "auto">

The column number the grid item should start at.

gridColumnEndResponsiveVariant<number | "auto">

The column number the grid item should end at.

gridRowResponsiveVariant<`span ${string}` | `span ${number}` | "auto" | `${number} / span ${string}` | `${number} / span ${number}` | `${number} / ${number}`>

The row number the grid item should span.

gridRowStartResponsiveVariant<number | "auto">

The row number the grid item should start at.

gridRowEndResponsiveVariant<number | "auto">

The row number the grid item should end at.

gridAreaResponsiveVariant<string>
alignSelfConditionalValue<WithEscapeHatch<OnlyKnown<"alignSelf", `var(--${string})` | AlignSelf | readonly string[] | undefined>>> | undefined

The align-self CSS property overrides a grid or flex item’s align-items value. In Grid, it aligns the item inside the grid area. In Flexbox, it aligns the item on the cross axis.

Syntax: auto | normal | stretch | <baseline-position> | <overflow-position>? <self-position>

justifySelfConditionalValue<AnyString | readonly string[] | JustifySelf | undefined>

The CSS justify-self property sets the way a box is justified inside its alignment container along the appropriate axis.

Syntax: auto | normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ]

gapResponsiveVariant<keyof CoralSpacing>

Sets the gaps (gutters) between rows and columns

rowGapResponsiveVariant<keyof CoralSpacing>

Sets the gaps (gutters) between rows

columnGapResponsiveVariant<keyof CoralSpacing>

Sets the gaps (gutters) between columns

gridTemplateColumnsConditionalValue<AnyString | GridTemplateColumns<String | Number> | readonly NonNullable<GridTemplateColumns<String | Number> | undefined>[] | undefined>
gridTemplateRowsConditionalValue<AnyString | GridTemplateRows<String | Number> | readonly NonNullable<GridTemplateRows<String | Number> | undefined>[] | undefined>
Last updated on