feat(html): add aria-labelledby helper
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
97a48fc73d
commit
264ecc3f84
3 changed files with 17 additions and 0 deletions
|
|
@ -36,6 +36,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns:
|
|||
|
||||
- `AriaLabel(node, label)`
|
||||
- `AriaDescribedBy(node, ids...)`
|
||||
- `AriaLabelledBy(node, ids...)`
|
||||
- `Role(node, role)`
|
||||
- `Alt(node, text)`
|
||||
- `AriaHidden(node, hidden)`
|
||||
|
|
|
|||
6
node.go
6
node.go
|
|
@ -175,6 +175,12 @@ func AriaDescribedBy(n Node, ids ...string) Node {
|
|||
return Attr(n, "aria-describedby", strings.Join(ids, " "))
|
||||
}
|
||||
|
||||
// AriaLabelledBy sets the aria-labelledby attribute on an element node.
|
||||
// Multiple IDs are joined with spaces, matching the HTML attribute format.
|
||||
func AriaLabelledBy(n Node, ids ...string) Node {
|
||||
return Attr(n, "aria-labelledby", strings.Join(ids, " "))
|
||||
}
|
||||
|
||||
// Role sets the role attribute on an element node.
|
||||
func Role(n Node, role string) Node {
|
||||
return Attr(n, "role", role)
|
||||
|
|
|
|||
10
node_test.go
10
node_test.go
|
|
@ -252,6 +252,16 @@ func TestAriaDescribedByHelper(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAriaLabelledByHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := AriaLabelledBy(El("input"), "label-1", "label-2")
|
||||
got := node.Render(ctx)
|
||||
want := `<input aria-labelledby="label-1 label-2">`
|
||||
if got != want {
|
||||
t.Errorf("AriaLabelledBy() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := Role(El("button", Raw("menu")), "navigation")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue