Skip to content
Forms, switch product

Grid

Grid is the one Layout Field for arranging other widgets. It stacks them, puts them side by side in a row or wraps them in columns. In a row or in columns, it lines up the labels, the controls and the errors of the fields next to each other, so a long label or an error never moves the controls beside it.

With no props, a grid stacks its children, one below the other:

grid.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.inputs.textInput('c1', {
label: 'First field',
uid: 'c1',
}),
gui.inputs.textInput('c2', {
label: 'Second field',
uid: 'c2',
}),
], {
uid: 'grid_stack',
}),
];
grid.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_stack",
"kind": "layout",
"type": "grid",
"children": [
{
"uid": "c1",
"kind": "input",
"type": "textinput",
"path": "c1",
"label": "First field"
},
{
"uid": "c2",
"kind": "input",
"type": "textinput",
"path": "c2",
"label": "Second field"
}
]
}
]
}

Use these props to customize your Grid widget.

proptypedescription
columnsnumber | autoWraps the children in that many equal columns, from 1 to 12, or in as many as fit with 'auto'. Overrides direction
directionstring'column' stacks the children; 'row' puts them on one line. Defaults to 'column'
gapstringThe space between the children: 'none', 'xs', 'sm', 'md', 'lg' or 'xl'. Defaults to 'md'
justifystringIn a row: 'stretch' shares the width by each child’s size; 'start', 'center', 'end' and 'space-between' keep each child at its own width and place them. Defaults to 'stretch'

In the DSL, gui.layouts.horizontalGrid is a row and gui.layouts.verticalGrid a stack. See the gui.layouts reference. Every prop also takes state suffixes, such as "direction.compact": "column".

Set direction to "row" to put the children side by side, sharing the width equally.

grid.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.inputs.textInput('r1', {
label: 'Left Field',
uid: 'r1',
}),
gui.inputs.textInput('r2', {
label: 'Right Field',
uid: 'r2',
}),
], {
direction: 'row',
uid: 'grid_row',
}),
];
grid.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_row",
"kind": "layout",
"type": "grid",
"props": {
"direction": "row"
},
"children": [
{
"uid": "r1",
"kind": "input",
"type": "textinput",
"path": "r1",
"label": "Left Field"
},
{
"uid": "r2",
"kind": "input",
"type": "textinput",
"path": "r2",
"label": "Right Field"
}
]
}
]
}

In a row, a child’s size sets its share of the width: a child with size: 2 is twice as wide as one with the default size of 1.

grid.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.inputs.textInput('s1', {
label: 'Default Size (1)',
uid: 's1',
}),
gui.inputs.textInput('s2', {
label: 'Size 2',
size: 2,
uid: 's2',
}),
], {
direction: 'row',
uid: 'grid_sizes',
}),
];
grid.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_sizes",
"kind": "layout",
"type": "grid",
"props": {
"direction": "row"
},
"children": [
{
"uid": "s1",
"kind": "input",
"type": "textinput",
"path": "s1",
"label": "Default Size (1)"
},
{
"uid": "s2",
"kind": "input",
"type": "textinput",
"path": "s2",
"label": "Size 2",
"size": 2
}
]
}
]
}

Set columns to a number from 1 to 12 to wrap the children in that many equal columns. They fill the columns in order, and a child with a size spans that many of them.

grid.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.inputs.textInput('street', {
label: 'Street',
size: 2,
uid: 'street',
}),
gui.inputs.textInput('floor', {
label: 'Floor',
uid: 'floor',
}),
gui.inputs.textInput('city', {
label: 'City',
uid: 'city',
}),
gui.inputs.textInput('postcode', {
label: 'Postcode',
uid: 'postcode',
}),
gui.inputs.textInput('country', {
label: 'Country',
uid: 'country',
}),
], {
columns: 3,
uid: 'grid_columns',
}),
];
grid.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_columns",
"kind": "layout",
"type": "grid",
"props": {
"columns": 3
},
"children": [
{
"uid": "street",
"kind": "input",
"type": "textinput",
"path": "street",
"label": "Street",
"size": 2
},
{
"uid": "floor",
"kind": "input",
"type": "textinput",
"path": "floor",
"label": "Floor"
},
{
"uid": "city",
"kind": "input",
"type": "textinput",
"path": "city",
"label": "City"
},
{
"uid": "postcode",
"kind": "input",
"type": "textinput",
"path": "postcode",
"label": "Postcode"
},
{
"uid": "country",
"kind": "input",
"type": "textinput",
"path": "country",
"label": "Country"
}
]
}
]
}

With columns: "auto", the grid fits as many columns as there is room for, each at least 12rem wide (the --gui-layout-column-min token), and wraps the rest onto new lines. size has no effect here.

grid.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.inputs.textInput('email', {
label: 'Email',
uid: 'email',
}),
gui.inputs.textInput('phone', {
label: 'Phone',
uid: 'phone',
}),
gui.inputs.textInput('website', {
label: 'Website',
uid: 'website',
}),
gui.inputs.textInput('company', {
label: 'Company',
uid: 'company',
}),
gui.inputs.textInput('jobTitle', {
label: 'Job title',
uid: 'jobTitle',
}),
], {
columns: 'auto',
uid: 'grid_columns_auto',
}),
];
grid.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_columns_auto",
"kind": "layout",
"type": "grid",
"props": {
"columns": "auto"
},
"children": [
{
"uid": "email",
"kind": "input",
"type": "textinput",
"path": "email",
"label": "Email"
},
{
"uid": "phone",
"kind": "input",
"type": "textinput",
"path": "phone",
"label": "Phone"
},
{
"uid": "website",
"kind": "input",
"type": "textinput",
"path": "website",
"label": "Website"
},
{
"uid": "company",
"kind": "input",
"type": "textinput",
"path": "company",
"label": "Company"
},
{
"uid": "jobTitle",
"kind": "input",
"type": "textinput",
"path": "jobTitle",
"label": "Job title"
}
]
}
]
}

gap sets the space between the children, in steps of the spacing scale:

gapSpace
none0
xs0.25rem
sm0.5rem
md1rem (default)
lg1.5rem
xl2rem
grid.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.inputs.textInput('g1', {
label: 'Field 1',
uid: 'g1',
}),
gui.inputs.textInput('g2', {
label: 'Field 2',
uid: 'g2',
}),
gui.inputs.textInput('g3', {
label: 'Field 3',
uid: 'g3',
}),
gui.inputs.textInput('g4', {
label: 'Field 4',
uid: 'g4',
}),
], {
columns: 2,
gap: 'xl',
uid: 'grid_gaps',
}),
];
grid.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_gaps",
"kind": "layout",
"type": "grid",
"props": {
"columns": 2,
"gap": "xl"
},
"children": [
{
"uid": "g1",
"kind": "input",
"type": "textinput",
"path": "g1",
"label": "Field 1"
},
{
"uid": "g2",
"kind": "input",
"type": "textinput",
"path": "g2",
"label": "Field 2"
},
{
"uid": "g3",
"kind": "input",
"type": "textinput",
"path": "g3",
"label": "Field 3"
},
{
"uid": "g4",
"kind": "input",
"type": "textinput",
"path": "g4",
"label": "Field 4"
}
]
}
]
}

In a row, any justify other than "stretch" keeps each child at its own width and places them along the row. "end" is the usual way to put the form’s buttons on the right:

grid.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.actions.button({
variant: 'outlined',
label: 'Cancel',
uid: 'cancel',
}),
gui.actions.button({
label: 'Save',
uid: 'save',
}),
], {
direction: 'row',
justify: 'end',
uid: 'grid_justify',
}),
];
grid.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_justify",
"kind": "layout",
"type": "grid",
"props": {
"direction": "row",
"justify": "end"
},
"children": [
{
"uid": "cancel",
"kind": "action",
"type": "button",
"label": "Cancel",
"props": {
"variant": "outlined"
}
},
{
"uid": "save",
"kind": "action",
"type": "button",
"label": "Save"
}
]
}
]
}

In a row or in columns, each child spans three tracks shared with the rest of its row: the label and hint, then the control, then the errors. So the controls stay level whatever the length of each label, and an error only grows the last track. Checkboxes, toggles and buttons sit at the vertical center of the controls. No props are needed for any of this.

grid-alignment.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.inputs.textInput('cardName', {
hint: 'As it is printed',
label: 'Name on the card',
uid: 'cardName',
}),
gui.inputs.textInput('cardNumber', {
label: 'Card number, sixteen digits without spaces',
uid: 'cardNumber',
}),
gui.inputs.checkbox('saveCard', {
label: 'Save this card',
uid: 'saveCard',
}),
], {
direction: 'row',
uid: 'grid_alignment',
}),
];
grid-alignment.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_alignment",
"kind": "layout",
"type": "grid",
"props": {
"direction": "row"
},
"children": [
{
"uid": "cardName",
"kind": "input",
"type": "textinput",
"path": "cardName",
"label": "Name on the card",
"props": {
"hint": "As it is printed"
}
},
{
"uid": "cardNumber",
"kind": "input",
"type": "textinput",
"path": "cardNumber",
"label": "Card number, sixteen digits without spaces"
},
{
"uid": "saveCard",
"kind": "input",
"type": "checkbox",
"path": "saveCard",
"label": "Save this card"
}
]
}
]
}

Fields that need height of their own, such as a textarea, a list or a calendar, line up the same way, but the row’s control track takes the height of the tallest control. Give them a row of their own, or a full row in a columns grid.

A grid can be the child of another grid. Here, a stack holds two rows, and each row lines up its own fields:

grid-nested.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.grid([
gui.layouts.grid([
gui.inputs.textInput('n1', {
label: 'First Name',
uid: 'n1',
}),
gui.inputs.textInput('n2', {
label: 'Last Name',
uid: 'n2',
}),
], {
direction: 'row',
uid: 'grid_row_1',
}),
gui.layouts.grid([
gui.inputs.textInput('n3', {
label: 'Email',
uid: 'n3',
}),
gui.inputs.textInput('n4', {
label: 'Phone',
size: 2,
uid: 'n4',
}),
], {
direction: 'row',
uid: 'grid_row_2',
}),
], {
uid: 'grid_outer',
}),
];
grid-nested.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "grid_outer",
"kind": "layout",
"type": "grid",
"children": [
{
"uid": "grid_row_1",
"kind": "layout",
"type": "grid",
"props": {
"direction": "row"
},
"children": [
{
"uid": "n1",
"kind": "input",
"type": "textinput",
"path": "n1",
"label": "First Name"
},
{
"uid": "n2",
"kind": "input",
"type": "textinput",
"path": "n2",
"label": "Last Name"
}
]
},
{
"uid": "grid_row_2",
"kind": "layout",
"type": "grid",
"props": {
"direction": "row"
},
"children": [
{
"uid": "n3",
"kind": "input",
"type": "textinput",
"path": "n3",
"label": "Email"
},
{
"uid": "n4",
"kind": "input",
"type": "textinput",
"path": "n4",
"label": "Phone",
"size": 2
}
]
}
]
}
]
}

Every grid stacks its children when the form is narrower than 480px. It measures the form, not the window, so a form in a narrow sidebar stacks on a wide screen too.

These props from GolemUI 1.x still work, and map to the props above. v3.0.0 removes them, so move to the new ones:

DeprecatedUse instead
autoFitcolumns. autoFit: false is columns: 12; true is a row
columnGap, rowGapgap. Pixels become the nearest step
alignjustify. space-around and space-evenly become space-between

The Flex layout is deprecated too, renders as a grid, and v3.0.0 removes it. The migration guide has the details.

Grid layouts can be styled as explained in the Styling Guide. The grid is the gui-grid classes of GolemUI Components, documented on its Grid page.

CSS VariableDescription
--gui-layout-gap-none … --gui-layout-gap-xlThe space of each gap step
--gui-layout-column-minThe narrowest column of a columns: "auto" grid

This is the anatomy of the Grid Widget in case you want to use your CSS styles.

grid-anatomy.html
<gui-grid-layout class="gui-field">
<div class="gui-grid gui-grid--row" id="grid_uid">
<div class="gui-grid__cell">
<!-- Child 1 -->
</div>
<div class="gui-grid__cell gui-grid__cell--span-2">
<!-- Child 2 (size: 2) -->
</div>
</div>
</gui-grid-layout>