feat(html): add aria-modal helper
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
94833edf43
commit
de3a40000c
4 changed files with 28 additions and 2 deletions
|
|
@ -53,6 +53,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns:
|
|||
- `AriaHidden(node, hidden)`
|
||||
- `AriaExpanded(node, expanded)`
|
||||
- `AriaDisabled(node, disabled)`
|
||||
- `AriaModal(node, modal)`
|
||||
- `AriaChecked(node, checked)`
|
||||
- `AriaInvalid(node, invalid)`
|
||||
- `AriaRequired(node, required)`
|
||||
|
|
|
|||
|
|
@ -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`, `AriaDisabled`, `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`, `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()`, `AriaHidden()`, `Hidden()`, `AriaDisabled()`, `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()`, `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
|
|
@ -389,6 +389,15 @@ func AriaDisabled(n Node, disabled bool) Node {
|
|||
return Attr(n, "aria-disabled", "false")
|
||||
}
|
||||
|
||||
// node.go: AriaModal sets the aria-modal attribute on an element node.
|
||||
// Example: AriaModal(El("dialog"), true).
|
||||
func AriaModal(n Node, modal bool) Node {
|
||||
if modal {
|
||||
return Attr(n, "aria-modal", "true")
|
||||
}
|
||||
return Attr(n, "aria-modal", "false")
|
||||
}
|
||||
|
||||
// node.go: AriaChecked sets the aria-checked attribute on an element node.
|
||||
// Example: AriaChecked(El("input"), true).
|
||||
func AriaChecked(n Node, checked bool) Node {
|
||||
|
|
|
|||
16
node_test.go
16
node_test.go
|
|
@ -706,6 +706,22 @@ func TestAriaDisabledHelper(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAriaModalHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
|
||||
modal := AriaModal(El("dialog", Raw("content")), true)
|
||||
gotModal := modal.Render(ctx)
|
||||
if !strings.Contains(gotModal, `aria-modal="true"`) {
|
||||
t.Errorf("AriaModal(true) = %q, want aria-modal=\"true\"", gotModal)
|
||||
}
|
||||
|
||||
nonModal := AriaModal(El("dialog", Raw("content")), false)
|
||||
gotNonModal := nonModal.Render(ctx)
|
||||
if !strings.Contains(gotNonModal, `aria-modal="false"`) {
|
||||
t.Errorf("AriaModal(false) = %q, want aria-modal=\"false\"", gotNonModal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAriaCheckedHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue