feat(html): add lang helper
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
25dc761d0b
commit
f8558a52ef
3 changed files with 17 additions and 0 deletions
|
|
@ -38,6 +38,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns:
|
|||
- `AriaDescribedBy(node, ids...)`
|
||||
- `AriaLabelledBy(node, ids...)`
|
||||
- `Role(node, role)`
|
||||
- `Lang(node, locale)`
|
||||
- `Alt(node, text)`
|
||||
- `AriaHidden(node, hidden)`
|
||||
- `TabIndex(node, index)`
|
||||
|
|
|
|||
6
node.go
6
node.go
|
|
@ -202,6 +202,12 @@ func Role(n Node, role string) Node {
|
|||
return Attr(n, "role", role)
|
||||
}
|
||||
|
||||
// node.go: Lang sets the lang attribute on an element node.
|
||||
// Example: Lang(El("html"), "en-GB").
|
||||
func Lang(n Node, locale string) Node {
|
||||
return Attr(n, "lang", locale)
|
||||
}
|
||||
|
||||
// node.go: Alt sets the alt attribute on an element node.
|
||||
// Example: Alt(El("img"), "Product screenshot").
|
||||
func Alt(n Node, text string) Node {
|
||||
|
|
|
|||
10
node_test.go
10
node_test.go
|
|
@ -273,6 +273,16 @@ func TestRoleHelper(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLangHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := Lang(El("html", Raw("content")), "en-GB")
|
||||
got := node.Render(ctx)
|
||||
want := `<html lang="en-GB">content</html>`
|
||||
if got != want {
|
||||
t.Errorf("Lang() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAltHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := Alt(El("img"), `A "quoted" caption`)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue