Skip to content
Forms, switch product

Sizing custom widgets

A custom widget doesn’t size itself. The Grid layout puts each of its children in a cell, and the cell applies the child’s size. Your widget fills its cell, so its render code doesn’t need to read templateData.size.

gui.layouts.horizontalGrid([
gui.inputs.custom('productRating', 'rating', { size: 1 }),
gui.actions.custom('productShare', { size: 2, onClick: () => 'shareEvent' }),
]);
{
"kind": "layout",
"type": "grid",
"props": { "direction": "row" },
"children": [
{
"kind": "input",
"type": "productRating",
"path": "rating",
"props": { "size": 1 }
},
{
"kind": "action",
"type": "productShare",
"props": { "size": 2 },
"on": { "click": "shareEvent" }
}
]
}

Here, the rating widget takes one part of the row and the share widget two.

size applies to custom and built-in widgets alike:

  • In a row (direction: 'row'), the children share the width by their size.
  • In numbered columns (columns: 3, for example), a child spans size columns.
  • In a stack, in columns: 'auto' and in a row with a justify, it has no effect: each child takes the full width, one column, or its own width.

In a row or in columns, the grid lines up the label, the control and the errors of each field with those of its neighbors. A custom input joins in when its root element has the gui-field class and its parts have these classes:

<div class="product-rating gui-field">
<label class="gui-label">Rating</label>
<div class="gui-widget"><!-- the stars --></div>
<div class="gui-validator"><!-- the errors --></div>
</div>

Without them, the widget spans the label, control and error tracks of its row from the top, as a nested layout does. GolemUI Components’ Grid page explains the tracks.

In 1.x, every custom widget set an inline flex style from templateData.size, because the Flex layout sized its children that way. Remove that code: the migration guide shows it for each framework.