feat(html): add dir helper
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Add a Dir convenience helper for the dir attribute so RTL/text-direction markup can be applied without raw Attr calls.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 17:42:50 +00:00
parent 4d767fa0bd
commit d0e7f60dab
3 changed files with 17 additions and 0 deletions

View file

@ -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)`

View file

@ -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 {

View file

@ -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 := `<p dir="rtl">مرحبا</p>`
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`)