diff --git a/docs/architecture.md b/docs/architecture.md index 23800b8..b45323c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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)` diff --git a/node.go b/node.go index de832e1..2d4aefa 100644 --- a/node.go +++ b/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 { diff --git a/node_test.go b/node_test.go index 3adc770..2566846 100644 --- a/node_test.go +++ b/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 := `content` + 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`)