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.
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
Choose something else when
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
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.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
label | Child | Required | Fieldset legend. |
value | ObjectFieldValue | Required | Controlled JSON-compatible object. |
valueKinds | ObjectFieldValueKind[] | — | Allowed row types. |
showRaw | boolean | — | Enables the advanced JSON escape hatch. |
error | Child | — | 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
| Property | Type | Required | Description |
|---|---|---|---|
className | string | No | Optional class hook applied to the public root element owned by the component. |
label | Child | Yes | Fieldset legend. |
value | ObjectFieldValue | Yes | Controlled JSON-compatible object. |
valueKinds | readonly ObjectFieldValueKind[] | No | Allowed row types. |
disabled | boolean | No | Inherited disabled attribute accepted by ObjectField. |
error | Child | No | Host validation message. |
showRaw | boolean | No | Enables the advanced JSON escape hatch. |
addLabel | Child | No | Inherited addLabel attribute accepted by ObjectField. |
rawLabel | Child | 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
| Concern | Contract |
|---|---|
| State | Use value to supply rendered state. Update it through the documented callback or native event handler. |
| DOM target | Native input attributes target the owned form control; wrapper-specific props stay on the documented component root. |
Anatomy and related components
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
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | forms |
| Component import | @tavojs/ui/object-field |
| Explicit CSS import | @tavojs/ui/css/object-field |
| Preview | Interactive preview available on this page |