fix(html): trim helper tokens
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
3375ad0b22
commit
3c64352a3b
2 changed files with 23 additions and 2 deletions
5
node.go
5
node.go
|
|
@ -355,10 +355,11 @@ func joinNonEmpty(parts ...string) string {
|
|||
|
||||
var filtered []string
|
||||
for i := range parts {
|
||||
if parts[i] == "" {
|
||||
part := strings.TrimSpace(parts[i])
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, parts[i])
|
||||
filtered = append(filtered, part)
|
||||
}
|
||||
if len(filtered) == 0 {
|
||||
return ""
|
||||
|
|
|
|||
20
node_test.go
20
node_test.go
|
|
@ -275,6 +275,16 @@ func TestAriaDescribedByHelper_IgnoresEmptyIDs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAriaDescribedByHelper_IgnoresWhitespaceIDs(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := AriaDescribedBy(El("input"), " ", "hint-1", "\t", "hint-2")
|
||||
got := node.Render(ctx)
|
||||
want := `<input aria-describedby="hint-1 hint-2">`
|
||||
if got != want {
|
||||
t.Errorf("AriaDescribedBy() with whitespace IDs = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAriaLabelledByHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := AriaLabelledBy(El("input"), "label-1", "label-2")
|
||||
|
|
@ -452,6 +462,16 @@ func TestClassHelper_IgnoresEmptyClasses(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestClassHelper_IgnoresWhitespaceClasses(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
node := Class(El("div", Raw("content")), " ", "card", "\t", "card--primary")
|
||||
got := node.Render(ctx)
|
||||
want := `<div class="card card--primary">content</div>`
|
||||
if got != want {
|
||||
t.Errorf("Class() with whitespace classes = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAriaHiddenHelper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue