diff --git a/docs/architecture.md b/docs/architecture.md index b45323c..40bee78 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -39,6 +39,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns: - `AriaLabelledBy(node, ids...)` - `Role(node, role)` - `Lang(node, locale)` +- `Dir(node, direction)` - `Alt(node, text)` - `AriaHidden(node, hidden)` - `TabIndex(node, index)` diff --git a/node.go b/node.go index 0f2991e..c694378 100644 --- a/node.go +++ b/node.go @@ -208,6 +208,12 @@ func Lang(n Node, locale string) Node { return Attr(n, "lang", locale) } +// node.go: Dir sets the dir attribute on an element node. +// Example: Dir(El("p"), "rtl"). +func Dir(n Node, direction string) Node { + return Attr(n, "dir", direction) +} + // 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 37aa206..cab1f1a 100644 --- a/node_test.go +++ b/node_test.go @@ -283,6 +283,16 @@ func TestLangHelper(t *testing.T) { } } +func TestDirHelper(t *testing.T) { + ctx := NewContext() + node := Dir(El("p", Raw("مرحبا")), "rtl") + got := node.Render(ctx) + want := `
مرحبا
` + if got != want { + t.Errorf("Dir() = %q, want %q", got, want) + } +} + func TestAltHelper(t *testing.T) { ctx := NewContext() node := Alt(El("img"), `A "quoted" caption`)