You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: USAGE.md
+38-1Lines changed: 38 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,11 @@ API, node shape, layout and style — create schema from definition, render to D
11
11
-[Node Shape](#node-shape)
12
12
-[Layout and Style](#layout-and-style)
13
13
-[Void Tags and Special Elements](#void-tags-and-special-elements)
14
+
-[Security](#security)
15
+
-[Boolean Attributes](#boolean-attributes)
16
+
-[Form Elements](#form-elements)
17
+
-[SVG Attributes](#svg-attributes)
18
+
-[Accessibility](#accessibility)
14
19
-[API Reference](#api-reference)
15
20
-[Type Reference](#type-reference)
16
21
-[Reference](#reference)
@@ -107,6 +112,38 @@ Allowed keys are exactly the above. Extra keys cause validation to throw.
107
112
-**template** — Child nodes are appended to `element.content` (DocumentFragment), not to the template element itself.
108
113
-**svg** — SVG elements are created with `createElementNS(SVG_NS, type)`; descendants stay in SVG namespace when under an `svg` node.
109
114
115
+
## Security
116
+
117
+
-**Text content** — `content` is applied via `createTextNode()`, so it is safe from HTML injection. Do not interpret `content` as HTML.
118
+
-**Attributes** — `attrs` values are set with `setAttribute()` or property assignment. Do not pass unsanitized user input into `attrs` (e.g. `href`, `src`) without validation or sanitization. For strict policies, consider [Trusted Types](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) where supported.
119
+
120
+
## Boolean Attributes
121
+
122
+
These attributes are treated as boolean (MDN: presence = true, absence = false): `checked`, `disabled`, `readonly`, `selected`, `inert`, `hidden`. Use `true` or `false` (or string `'true'`/`'false'`). When the value is false, the attribute is removed from the DOM and the corresponding property is set to false; when true, only the property is set (no attribute string is written). This avoids invalid markup such as `disabled="false"` (which would still disable the element).
-**disabled** — Applied via property on `input`, `button`, `select`, `textarea`, `fieldset`, `optgroup`, and `option`. Boolean handling as above.
133
+
-**readonly** — Applied via `readOnly` property on `input` and `textarea`.
134
+
-**selected** — Applied via `selected` property on `option`.
135
+
-**checked** — Applied via `checked` property on `input` (e.g. checkbox/radio).
136
+
137
+
## SVG Attributes
138
+
139
+
Layout and style from the schema are applied only to HTML elements. For SVG nodes (e.g. `circle`, `rect`, `path` under `svg`), set dimensions and appearance via `attrs` (e.g. `attrs.fill`, `attrs.stroke`, `attrs.width`, `attrs.height`, or `attrs.viewBox` on `svg`). Use `attrs.style` for a CSS string if needed.
140
+
141
+
## Accessibility
142
+
143
+
- Prefer **semantic HTML** (`type: 'header'`, `main`, `nav`, `button`, etc.) so built-in roles and behavior are available.
144
+
-**ARIA** — Pass ARIA attributes through `attrs` (e.g. `attrs['aria-label']`, `attrs['aria-live']`, `attrs['aria-hidden']`). For dynamic content that updates without a full re-render, consider `aria-live` regions so assistive technologies can announce changes.
145
+
-**inert** and **hidden** — Supported as boolean attributes (see [Boolean Attributes](#boolean-attributes)) for visibility and focus behavior.
146
+
110
147
## API Reference
111
148
112
149
### create(definition)
@@ -134,7 +171,7 @@ Types are re-exported under the `Types` namespace: `import type * as Types from
134
171
-**Node:** Object with `type` (string) and optional `id`, `layout`, `style`, `attrs`, `content`, `src`, `alt`, `children` (readonly array of Node). Void tags must not have `children`.
-**Attrs:**`Record<string, string | number | boolean>` — HTML attributes. Special handling for `class`/`className`, `style` (string), `value`, `checked`, `disabled`on form elements.
174
+
-**Attrs:**`Record<string, string | number | boolean>` — HTML attributes. Special handling for `class`/`className`, `style` (string), `value`, and boolean attributes (`checked`, `disabled`, `readonly`, `selected`, `inert`, `hidden`) on the relevant elements.
138
175
-**Schema2UIDefault:**`{ create, render }` — shape returned when calling the default export. **Schema2UIDefaultExport:** callable with `.create`, `.render`, `.el`; calling it returns `Schema2UIDefault & { el: El }`.
0 commit comments