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 scope styles for picture element in Picture component #10975

Merged
merged 2 commits into from May 9, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented May 8, 2024

Changes

fix #10307

The PR uses some tricks to get the scoped attributes or class to pass it to the <picture> element, instead of only to the img element.

The trick uses regexes for astro-* class and data-astro-cid-* attributes, which perhaps is not the most elegant, but I think it should be fine?

Question: Do we want to check for data-astro-cid specifically?

Testing

Added test

Docs

Added changeset

Copy link

changeset-bot bot commented May 8, 2024

🦋 Changeset detected

Latest commit: 9b012c4

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label May 8, 2024
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I am not sure this solution will be future-proof, especially if in the future we will land withastro/roadmap#243

However, I don't know if there's a better solution, so I leave the final call to you

}
}
for (const key in props) {
if (key.startsWith('data-astro-cid')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

😔

@bluwy
Copy link
Member Author

bluwy commented May 9, 2024

Yeah if we want to support the feature request and not break this, we would probably need to support some kind of Astro.scopedProps API and restrict the hash config to string-form like cssHash: 'myhash-[hash:8]' in order to continue making this work.

I don't think this is perfect too, but I think it enables a nice usecase and we could try to revisit this again. I'll take the approvals as a green light though 😄

@bluwy bluwy merged commit 6b640b3 into main May 9, 2024
13 checks passed
@bluwy bluwy deleted the picture-scope-style branch May 9, 2024 13:04
@astrobot-houston astrobot-houston mentioned this pull request May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Styles contained in SCSS class passed to <Picture /> component's pictureAttributes.class not being applied
3 participants