feat(html): add aria-disabled helper
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 18:28:49 +00:00
parent ec18122233
commit 7091a5f341
4 changed files with 28 additions and 2 deletions

View file

@ -46,6 +46,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns:
- `Class(node, classes...)`
- `AriaHidden(node, hidden)`
- `AriaExpanded(node, expanded)`
- `AriaDisabled(node, disabled)`
- `TabIndex(node, index)`
- `AutoFocus(node)`

View file

@ -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` |
| `node.go` | `Node` interface and all node types: `El`, `Text`, `Raw`, `If`, `Unless`, `Each`, `EachSeq`, `Switch`, `Entitled`, plus `AriaLabel`, `AltText`, `AriaDisabled`, `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 helpers such as `AriaLabel()`, `AriaControls()`, `AriaCurrent()`, `AriaHidden()`, 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 helpers such as `AriaLabel()`, `AriaControls()`, `AriaCurrent()`, `AriaHidden()`, `AriaDisabled()`, 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`.

View file

@ -263,6 +263,15 @@ func AriaExpanded(n Node, expanded bool) Node {
return Attr(n, "aria-expanded", "false")
}
// node.go: AriaDisabled sets the aria-disabled attribute on an element node.
// Example: AriaDisabled(El("button"), true).
func AriaDisabled(n Node, disabled bool) Node {
if disabled {
return Attr(n, "aria-disabled", "true")
}
return Attr(n, "aria-disabled", "false")
}
// node.go: TabIndex sets the tabindex attribute on an element node.
// Example: TabIndex(El("button"), 0).
func TabIndex(n Node, index int) Node {

View file

@ -386,6 +386,22 @@ func TestAriaExpandedHelper(t *testing.T) {
}
}
func TestAriaDisabledHelper(t *testing.T) {
ctx := NewContext()
disabled := AriaDisabled(El("button", Raw("menu")), true)
gotDisabled := disabled.Render(ctx)
if !strings.Contains(gotDisabled, `aria-disabled="true"`) {
t.Errorf("AriaDisabled(true) = %q, want aria-disabled=\"true\"", gotDisabled)
}
enabled := AriaDisabled(El("button", Raw("menu")), false)
gotEnabled := enabled.Render(ctx)
if !strings.Contains(gotEnabled, `aria-disabled="false"`) {
t.Errorf("AriaDisabled(false) = %q, want aria-disabled=\"false\"", gotEnabled)
}
}
func TestTabIndexHelper(t *testing.T) {
ctx := NewContext()
node := TabIndex(El("button", Raw("action")), -1)