Skip to content

Commit d5dbddf

Browse files
committed
docs(usage): security, boolean/form/SVG, accessibility 🚧
- Add Security, Boolean Attributes, Form Elements, SVG Attributes, Accessibility sections and TOC - Update Attrs type description for boolean attrs
1 parent 73c8874 commit d5dbddf

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

USAGE.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ API, node shape, layout and style — create schema from definition, render to D
1111
- [Node Shape](#node-shape)
1212
- [Layout and Style](#layout-and-style)
1313
- [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)
1419
- [API Reference](#api-reference)
1520
- [Type Reference](#type-reference)
1621
- [Reference](#reference)
@@ -107,6 +112,38 @@ Allowed keys are exactly the above. Extra keys cause validation to throw.
107112
- **template** — Child nodes are appended to `element.content` (DocumentFragment), not to the template element itself.
108113
- **svg** — SVG elements are created with `createElementNS(SVG_NS, type)`; descendants stay in SVG namespace when under an `svg` node.
109114

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).
123+
124+
```typescript
125+
{ type: 'input', attrs: { checked: false } } // unchecked, no checked attribute
126+
{ type: 'button', attrs: { disabled: true } } // disabled
127+
{ type: 'div', attrs: { hidden: false } } // visible, no hidden attribute
128+
```
129+
130+
## Form Elements
131+
132+
- **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+
110147
## API Reference
111148

112149
### create(definition)
@@ -134,7 +171,7 @@ Types are re-exported under the `Types` namespace: `import type * as Types from
134171
- **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`.
135172
- **Layout:** Optional `width`, `height`, `x`, `y`, `flex`, `gap` — each `number | string`.
136173
- **Style:** Optional `border`, `borderRadius`, `boxShadow`, `color`, `fill`, `font`, `margin`, `opacity`, `padding`, `stroke`, `transition` — each `string`.
137-
- **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.
138175
- **Schema2UIDefault:** `{ create, render }` — shape returned when calling the default export. **Schema2UIDefaultExport:** callable with `.create`, `.render`, `.el`; calling it returns `Schema2UIDefault & { el: El }`.
139176

140177
## Reference

0 commit comments

Comments
 (0)