Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the class attribute for hero action link buttons #2253

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-rats-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes an issue preventing to use the `class` attribute in hero action link buttons.
14 changes: 8 additions & 6 deletions packages/starlight/components/Hero.astro
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ if (image) {
{
actions.length > 0 && (
<div class="sl-flex actions">
{actions.map(({ attrs, icon, link: href, text, variant }) => (
<LinkButton {href} {variant} icon={icon?.name} {...attrs}>
{text}
{icon?.html && <Fragment set:html={icon.html} />}
</LinkButton>
))}
{actions.map(
({ attrs: { class: className, ...attrs } = {}, icon, link: href, text, variant }) => (
<LinkButton {href} {variant} icon={icon?.name} class:list={[className]} {...attrs}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, interesting! Do you know why this extra work is needed? Because Astro already sets a class and uses that instead of the one spread in from attrs? Feels like maybe something we should report to the team.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I always assumed this was the expected pattern to use with our scopedStyleStrategy when you want to accept a class that you would pass down to a child and the component also get a scoped class. Using class would result with one being overwritten by the other so you would have to use class:list. Thinking about it, I guess this may be handled automatically, never thought about it, could be a good question to ask 🤔

Copy link
Member

@delucis delucis Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asked on Discord, but I think we can still make this change as a fix for now!

{text}
{icon?.html && <Fragment set:html={icon.html} />}
</LinkButton>
)
)}
</div>
)
}
Expand Down
Loading