Navigated to /docs/ui/components/object-field

ObjectField

Structured JSON-compatible object property editor with validation.

Preview

A live, theme-aware example rendered with the published component.

Loading preview…

Import

Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.

TSX
tsximport { ObjectField } from "@tavojs/ui/object-field";

The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/object-field.

When to use

Use it when

Use `ObjectField` for JSON-compatible records whose keys, value types, values, and raw JSON need structured editing

Choose something else when

Avoid ObjectField when wrapping controls without labels or accessible names.

Examples

These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.

ObjectField example

TSXCreate: src/components/examples/ObjectFieldExample1.tsx
tsximport { createTavo } from "@tavojs/core";
import { ObjectField } from "@tavojs/ui/object-field";
import { Text } from "@tavojs/ui";
import type { ObjectFieldValue } from "@tavojs/ui/object-field";

type State = { options: ObjectFieldValue; message: string };

export const ObjectFieldExample1 = createTavo<Record<string, never>, State>({
  model: () => ({ options: { color: "primary", hidden: false }, message: "Edit an option" }),
  view: ({ state, model }) => (
    <>
      <ObjectField
        label="Options"
        value={state.options}
        valueKinds={["text", "number", "boolean", "object", "array", "null"]}
        onDraft={(options, validation) => {
          if (validation.valid) model.set("options", options);
        }}
        onCommit={(options, validation) => {
          if (validation.valid) model.patch({ options, message: "Options committed locally" });
        }}
      />
      <Text role="status">{state.message}</Text>
    </>
  )
});

Common props and defaults

A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
labelChild

Required

Fieldset legend.
valueObjectFieldValue

Required

Controlled JSON-compatible object.
valueKindsObjectFieldValueKind[]

Allowed row types.
showRawboolean

Enables the advanced JSON escape hatch.
errorChild

Host validation message.
onDraft(value, validation) => void

Transient valid-object draft and validation state.
onCommit(value, validation) => void

Valid structured commit.
onValidationChange(validation) => void

Duplicate-key, number, and JSON validation updates.

Complete TypeScript API

Import from @tavojs/ui/object-field. Published exports: ObjectField, ObjectFieldJsonPrimitive, ObjectFieldJsonValue, ObjectFieldProps, ObjectFieldValidation, ObjectFieldValidationIssue, ObjectFieldValue, ObjectFieldValueKind, validateObjectField, validateObjectFieldEntries.

ObjectFieldProps

PropertyTypeRequiredDescription
classNamestring

No

Optional class hook applied to the public root element owned by the component.

labelChild

Yes

Fieldset legend.

valueObjectFieldValue

Yes

Controlled JSON-compatible object.

valueKindsreadonly ObjectFieldValueKind[]

No

Allowed row types.

disabledboolean

No

Inherited disabled attribute accepted by ObjectField.

errorChild

No

Host validation message.

showRawboolean

No

Enables the advanced JSON escape hatch.

addLabelChild

No

Inherited addLabel attribute accepted by ObjectField.

rawLabelChild

No

Inherited rawLabel attribute accepted by ObjectField.

onDraft(value: ObjectFieldValue, validation: ObjectFieldValidation) => void

No

Transient valid-object draft and validation state.

onCommit(value: ObjectFieldValue, validation: ObjectFieldValidation) => void

No

Valid structured commit.

onValidationChange(validation: ObjectFieldValidation) => void

No

Duplicate-key, number, and JSON validation updates.

State ownership and DOM target

ConcernContract
StateUse value to supply rendered state. Update it through the documented callback or native event handler.
DOM targetNative input attributes target the owned form control; wrapper-specific props stay on the documented component root.

Anatomy and related components

This component exposes one public component root rather than a compound member API.

Limitations

Avoid ObjectField when wrapping controls without labels or accessible names.

Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.

Accessibility

Rows have explicit Key, Type, and Value labels; add/remove controls have accessible names; errors use alert semantics without moving focus.

  • Rows have explicit Key, Type, and Value labels; add/remove controls have accessible names; errors use alert semantics without moving focus.

Component status

ContractCurrent value
Maturitystable
Categoryforms
Component import@tavojs/ui/object-field
Explicit CSS import@tavojs/ui/css/object-field
PreviewInteractive preview available on this page