Render Options
render is how Ornata turns component state back into DOM output inside the component’s HTML contract. Each render callback returns a RenderOptions object for one resolved element or one item in a resolved element list.
Basic shape
Section titled “Basic shape”render: { value() { return { text: String(this.state.count), }; },}interface CounterElements { value: HTMLElement};
render: { value() { return { text: String(this.state.count), }; },}Available render outputs
Section titled “Available render outputs”Render callbacks can return: text, html, attributes, classes, style, dataset, and/or events. These options can be combined in a single render result.
Set text when you want to update textContent.
render: { label() { return { text: this.state.label, }; },}interface ExampleElements { label: HTMLElement;}
render: { label() { return { text: this.state.label, }; },}Set html when you want to update innerHTML.
render: { output() { return { html: `<strong>${this.state.message}</strong>`, }; },}interface ExampleElements { output: HTMLElement;}
render: { output() { return { html: `<strong>${this.state.message}</strong>`, }; },}attributes
Section titled “attributes”Use attributes for standard and boolean attributes.
render: { panel() { return { attributes: { hidden: !this.state.open, "aria-expanded": String(this.state.open), }, }; },}interface ExampleElements { panel: HTMLElement;}
render: { panel() { return { attributes: { hidden: !this.state.open, "aria-expanded": String(this.state.open), }, }; },}Behavior summary:
- string values set the attribute
trueadds a boolean attributefalseremoves a boolean attributenullremoves the attributeundefinedleaves it unchanged
classes
Section titled “classes”Use classes for class toggling.
render: { item() { return { classes: { "is-active": this.state.active, }, }; },}interface ExampleElements { item: HTMLElement;}
render: { item() { return { classes: { "is-active": this.state.active, }, }; },}Behavior summary:
trueadds the key to the class listfalseremoves the key from the class list
Use style for inline style updates.
render: { panel() { return { style: { display: this.state.open ? "block" : "none", }, }; },}interface ExampleElements { panel: HTMLElement;}
render: { panel() { return { style: { display: this.state.open ? "block" : "none", }, }; },}Behavior summary:
- string values set the style property
nullremoves the propertyundefinedleaves it unchanged
dataset
Section titled “dataset”Use dataset for data-* updates.
render: { item() { return { dataset: { state: this.state.active ? "active" : "idle", }, }; },}interface ExampleElements { item: HTMLElement;}
render: { item() { return { dataset: { state: this.state.active ? "active" : "idle", }, }; },}Behavior summary:
- string values set the dataset property
nullremoves the dataset propertyundefinedleaves it unchanged
events
Section titled “events”Use events to attach event handlers.
render: { button() { return { events: { click: () => this.methods.increment(), }, }; },}interface ExampleElements { button: HTMLButtonElement;}
render: { button() { return { events: { click: () => this.methods.increment(), }, }; },}Rendering lists with index
Section titled “Rendering lists with index”When the rendered element is an array, Ornata passes index in the render context.
render: { items({ index }) { const currentIndex = index ?? 0;
return { classes: { "is-active": currentIndex === this.state.activeIndex, }, }; },}interface ExampleElements { items: HTMLElement[];}
render: { items({ index }) { const currentIndex = index ?? 0;
return { classes: { "is-active": currentIndex === this.state.activeIndex, }, }; },}This is especially useful for:
- tabs
- menus
- repeated buttons
- repeated panels
- filtered or selected lists
A good mental model
Section titled “A good mental model”Render callbacks should describe DOM output, not general side effects or reusable business logic.
That usually means:
renderfor visual and attribute updateswatchfor internal side effects and more complex DOM updatesmethodsfor named reusable actions and event handlerscomputedfor derived state values