Inference Logoinference.sh

Label

Accessible label for a form field.

Preview

code
1Email2[________________]

Usage

go
1node := models.WidgetNode{2    Type:      models.WidgetNodeTypeLabel,3    Value:     "Email",4    FieldName: "email",5}

Props

NameTypeDescriptionDefault
type"label"Node typerequired
valuestringText content of the labelrequired
fieldNamestringName of the field this label describesrequired
sizestringSize token: xs, sm, md, lg, xl"sm"
weightstringFont weight: normal, medium, semibold, bold"medium"
colorstring | ThemeColorText color-
textAlignstringHorizontal alignment"start"

Examples

Basic Label

go
1{2    Type: models.WidgetNodeTypeCol,3    Gap:  1,4    Children: []models.WidgetNode{5        {Type: models.WidgetNodeTypeLabel, Value: "Email", FieldName: "email"},6        {Type: models.WidgetNodeTypeInput, Name: "email", Placeholder: "[email protected]"},7    },8}

Form with Labels

go
1widget := &models.Widget{2    Type:        models.WidgetTypeUI,3    Title:       "Contact Form",4    Interactive: true,5    Children: []models.WidgetNode{6        {7            Type: models.WidgetNodeTypeCol,8            Gap:  3,9            Children: []models.WidgetNode{10                // Name field11                {Type: models.WidgetNodeTypeCol, Gap: 1, Children: []models.WidgetNode{12                    {Type: models.WidgetNodeTypeLabel, Value: "Name", FieldName: "name"},13                    {Type: models.WidgetNodeTypeInput, Name: "name", Placeholder: "Your name"},14                }},15                // Email field16                {Type: models.WidgetNodeTypeCol, Gap: 1, Children: []models.WidgetNode{17                    {Type: models.WidgetNodeTypeLabel, Value: "Email", FieldName: "email"},18                    {Type: models.WidgetNodeTypeInput, Name: "email", Placeholder: "[email protected]"},19                }},20            },21        },22    },23    Actions: []models.WidgetActionButton{24        {Label: "Submit", Action: models.WidgetAction{Type: "submit"}},25    },26}

Label with Required Indicator

go
1{2    Type: models.WidgetNodeTypeRow,3    Gap:  1,4    Children: []models.WidgetNode{5        {Type: models.WidgetNodeTypeLabel, Value: "Password", FieldName: "password"},6        {Type: models.WidgetNodeTypeText, Value: "*", Variant: "muted"},7    },8}

TypeScript

typescript
1const node: WidgetNode = {2  type: "label",3  value: "Email",4  fieldName: "email",5}

Accessibility

Labels are important for accessibility:

  • Screen readers announce the label when the field is focused
  • Clicking the label focuses the associated input
  • The fieldName prop links the label to the input via the name attribute

Best Practices

  1. Always use with inputs - Every form field should have a label
  2. Keep labels short - 1-3 words
  3. Match fieldName to input name - Ensures proper association
  4. Stack vertically - Label above input is most readable

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.