fix(html): reserve responsive variant attribute
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
b6120a1929
commit
fde2f9b884
2 changed files with 23 additions and 0 deletions
|
|
@ -212,6 +212,9 @@ func (r *Responsive) renderWithPath(ctx *Context, path string) string {
|
|||
keys := slices.Collect(maps.Keys(r.attrs))
|
||||
slices.Sort(keys)
|
||||
for _, key := range keys {
|
||||
if key == "data-variant" {
|
||||
continue
|
||||
}
|
||||
b.WriteByte(' ')
|
||||
b.WriteString(escapeHTML(key))
|
||||
b.WriteString(`="`)
|
||||
|
|
|
|||
|
|
@ -158,6 +158,26 @@ func TestResponsive_Attributes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestResponsive_ReservedVariantAttributeIsIgnored(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
r := Attr(NewResponsive().
|
||||
Variant("desktop", NewLayout("C").C(Raw("main"))),
|
||||
"data-variant", "override",
|
||||
)
|
||||
|
||||
got := r.Render(ctx)
|
||||
|
||||
if count := strings.Count(got, `data-variant=`); count != 1 {
|
||||
t.Fatalf("responsive wrapper should emit exactly one data-variant attribute, got %d in:\n%s", count, got)
|
||||
}
|
||||
if !strings.Contains(got, `data-variant="desktop"`) {
|
||||
t.Fatalf("responsive wrapper should preserve its own variant name, got:\n%s", got)
|
||||
}
|
||||
if strings.Contains(got, `data-variant="override"`) {
|
||||
t.Fatalf("responsive wrapper should ignore reserved data-variant attrs, got:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVariantSelector(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue