feat(html): add dir helper
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:
parent
4d767fa0bd
commit
d0e7f60dab
3 changed files with 17 additions and 0 deletions
|
|
@ -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)`
|
||||
|
|
|
|||
6
node.go
6
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 {
|
||||
|
|
|
|||
10
node_test.go
10
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 := `<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`)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue