Skip to content

fix(button): separate custom attributes from role - #2118

Merged
markdumay merged 1 commit into
mainfrom
fix/button-attributes
Aug 4, 2026
Merged

fix(button): separate custom attributes from role#2118
markdumay merged 1 commit into
mainfrom
fix/button-attributes

Conversation

@markdumay

Copy link
Copy Markdown
Collaborator

Summary

assets/button.html rendered custom attributes glued to the role
attribute that follows them:

<a href="/downloads/spec.json" class="btn btn-primary"
    download="spec.json"role="button">

The range block emitted each pair with a leading space inside the
printf, but its closing {{- end -}} trimmed the newline separating the
last attribute from role="button". Browsers recover from the missing
separator, so the button still works, but the markup is invalid and any
consumer parsing the tag strictly sees a single mangled attribute.

Fix

Switch to the one-line form already used in assets/nav.html and
shortcodes/button-group.html, which keeps the separator outside the
printf and leaves the trailing whitespace intact:

{{- range $key, $val := $args.attributes }} {{ printf "%s=%q" $key $val | safeHTMLAttr }}{{ end }}
role="button"

assets/button.html was the only partial with this bug; nav.html and
button-group.html were already correct.

Test plan

Verified against a live site (infusal.io) by patching its vendored copy of
the partial and rebuilding:

  • A button with attributes (dict "download" "odcs-json-schema-v3.0.1.json")
    now renders download="…" and role="button" as separate attributes.
  • Buttons without custom attributes render byte-identical output — the empty
    range emitted nothing before and after.
  • pnpm test (lint + test:templates) passes.

🤖 Generated with Claude Code

The range over `attributes` emitted each pair with a leading space, but
its closing `-}}` swallowed the newline before role="button". A button
with a custom attribute therefore rendered `download="x"role="button"`.
Browsers recover from the missing separator, but the markup is invalid.

Use the one-line form already applied in assets/nav.html and
shortcodes/button-group.html: the separator sits outside the printf, so
the whitespace ahead of role="button" survives. Buttons without custom
attributes are unaffected.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@netlify

netlify Bot commented Aug 4, 2026

Copy link
Copy Markdown

Deploy Preview for gethinode-demo ready!

Name Link
🔨 Latest commit eb01f2e
🔍 Latest deploy log https://app.netlify.com/projects/gethinode-demo/deploys/6a719b5fc0e3390008ab0825
😎 Deploy Preview https://deploy-preview-2118--gethinode-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@markdumay
markdumay enabled auto-merge August 4, 2026 08:01
@markdumay
markdumay merged commit 5d0240f into main Aug 4, 2026
17 checks passed
@markdumay
markdumay deleted the fix/button-attributes branch August 4, 2026 08:02
@markdumay

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 3.18.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant