feat(html): add aria-atomic helper
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
3fa2a86664
commit
f828848cc0
4 changed files with 32 additions and 2 deletions
|
|
@ -44,6 +44,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns:
|
|||
- `AriaCurrent(node, current)`
|
||||
- `AriaBusy(node, busy)`
|
||||
- `AriaLive(node, live)`
|
||||
- `AriaAtomic(node, atomic)`
|
||||
- `AriaDescription(node, description)`
|
||||
- `AriaDetails(node, ids...)`
|
||||
- `AriaErrorMessage(node, ids...)`
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ This builds a Header-Content-Footer layout with semantic HTML elements (`<header
|
|||
|
||||
| Path | Purpose |
|
||||
|------|---------|
|
||||
| `node.go` | `Node` interface and all node types: `El`, `Text`, `Raw`, `If`, `Unless`, `Each`, `EachSeq`, `Switch`, `Entitled`, plus `AriaLabel`, `AriaControls`, `AriaHasPopup`, `AriaOwns`, `AriaKeyShortcuts`, `Alt`/`AltText`, `AriaBusy`, `AriaLive`, `AriaDescription`, `AriaDetails`, `AriaErrorMessage`, `AriaRoleDescription`, `AriaDisabled`, `AriaModal`, `AriaChecked`, `AriaInvalid`, `AriaRequired`, `AriaPressed`, `AriaSelected`, `Hidden`, `TabIndex`, and `AutoFocus` helpers |
|
||||
| `node.go` | `Node` interface and all node types: `El`, `Text`, `Raw`, `If`, `Unless`, `Each`, `EachSeq`, `Switch`, `Entitled`, plus `AriaLabel`, `AriaControls`, `AriaHasPopup`, `AriaOwns`, `AriaKeyShortcuts`, `Alt`/`AltText`, `AriaBusy`, `AriaLive`, `AriaAtomic`, `AriaDescription`, `AriaDetails`, `AriaErrorMessage`, `AriaRoleDescription`, `AriaDisabled`, `AriaModal`, `AriaChecked`, `AriaInvalid`, `AriaRequired`, `AriaPressed`, `AriaSelected`, `Hidden`, `TabIndex`, and `AutoFocus` helpers |
|
||||
| `layout.go` | HLCRF compositor with semantic HTML elements and ARIA roles |
|
||||
| `responsive.go` | Multi-variant breakpoint wrapper (`data-variant` containers, CSS scoping helpers) |
|
||||
| `context.go` | Rendering context: identity, locale, entitlements, i18n service |
|
||||
|
|
@ -52,7 +52,7 @@ This builds a Header-Content-Footer layout with semantic HTML elements (`<header
|
|||
|
||||
## Key Concepts
|
||||
|
||||
**Node tree** -- All renderable units implement `Node`, a single-method interface: `Render(ctx *Context) string`. The library composes nodes into trees using `El()` for elements, `Text()` for translated text, and control-flow constructors (`If`, `Unless`, `Each`, `Switch`, `Entitled`), plus accessibility and visibility helpers such as `AriaLabel()`, `AriaControls()`, `AriaHasPopup()`, `AriaOwns()`, `AriaKeyShortcuts()`, `AriaCurrent()`, `AriaBusy()`, `AriaLive()`, `AriaDescription()`, `AriaDetails()`, `AriaErrorMessage()`, `AriaRoleDescription()`, `AriaHidden()`, `Hidden()`, `AriaDisabled()`, `AriaModal()`, `AriaChecked()`, `AriaInvalid()`, `AriaRequired()`, `AriaReadOnly()`, and `TabIndex()`.
|
||||
**Node tree** -- All renderable units implement `Node`, a single-method interface: `Render(ctx *Context) string`. The library composes nodes into trees using `El()` for elements, `Text()` for translated text, and control-flow constructors (`If`, `Unless`, `Each`, `Switch`, `Entitled`), plus accessibility and visibility helpers such as `AriaLabel()`, `AriaControls()`, `AriaHasPopup()`, `AriaOwns()`, `AriaKeyShortcuts()`, `AriaCurrent()`, `AriaBusy()`, `AriaLive()`, `AriaAtomic()`, `AriaDescription()`, `AriaDetails()`, `AriaErrorMessage()`, `AriaRoleDescription()`, `AriaHidden()`, `Hidden()`, `AriaDisabled()`, `AriaModal()`, `AriaChecked()`, `AriaInvalid()`, `AriaRequired()`, `AriaReadOnly()`, and `TabIndex()`.
|
||||
|
||||
**HLCRF Layout** -- A five-slot compositor that maps to semantic HTML: `<header>` (H), `<aside>` (L/R), `<main>` (C), `<footer>` (F). The variant string controls which slots render: `"HLCRF"` for all five, `"HCF"` for three, `"C"` for content only. Layouts nest: placing a `Layout` inside another layout's slot produces hierarchical `data-block` paths like `L-0-C-0`.
|
||||
|
||||
|
|
|
|||
9
node.go
9
node.go
|
|
@ -289,6 +289,15 @@ func AriaLive(n Node, live string) Node {
|
|||
return n
|
||||
}
|
||||
|
||||
// node.go: AriaAtomic sets the aria-atomic attribute on a live region node.
|
||||
// Example: AriaAtomic(El("div"), true).
|
||||
func AriaAtomic(n Node, atomic bool) Node {
|
||||
if atomic {
|
||||
return Attr(n, "aria-atomic", "true")
|
||||
}
|
||||
return Attr(n, "aria-atomic", "false")
|
||||
}
|
||||
|
||||
// node.go: AriaDescription sets the aria-description attribute on an element node.
|
||||
// Example: AriaDescription(El("button"), "Opens the navigation menu").
|
||||
// An empty value leaves the node unchanged so callers can opt out cleanly.
|
||||
|
|
|
|||
20
node_test.go
20
node_test.go
|
|
@ -467,6 +467,26 @@ func TestAriaLiveHelper_IgnoresWhitespace(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAriaAtomicHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := AriaAtomic(El("div", Raw("updates")), true)
|
||||
got := node.Render(ctx)
|
||||
want := `<div aria-atomic="true">updates</div>`
|
||||
if got != want {
|
||||
t.Errorf("AriaAtomic(true) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAriaAtomicHelper_False(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := AriaAtomic(El("div", Raw("updates")), false)
|
||||
got := node.Render(ctx)
|
||||
want := `<div aria-atomic="false">updates</div>`
|
||||
if got != want {
|
||||
t.Errorf("AriaAtomic(false) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAriaDescriptionHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue