-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Emotion: Provider to increase className specificity #18483
Comments
Update!~ Will use |
Where do you see a need for this in our context? |
@youknowriad Sure thing! For example, the Taking a look at Gutenberg within WP Admin, specifically in the sidebar. In order to override the default input[type="text"],
...
textarea {
...
} The styles need to increase specificity to override (or reset), like this: .edit-post-header .input-control,
.edit-post-header input[type="text"],
... {
...
} Components (in this case Where this is tricky is: a. When the Emotion will generate a className like Wrapping the Gutenberg app with (Note: I always use Also, regardless of its React/DOM location, the Provider's scope (e.g. Hopefully this explanation helps! |
Thanks that is a good example and explanation. Now, say we are using a CSS-in-JS versioin of TextControl inside a component in block-editor that is not written in CSS-in-JS (say PostTitle just a random example) and I want to tweak the style of the TextControl inside that PostTitle specifically (I know we do these kind of things a lot in Gutenberg). Wouldn't this change make it harder to achieve? |
@youknowriad That's a great question! Had to really think about this. Even chatted about it with @diegohaz! In the case of
That would be stronger than the (scoped) generated Emotion styles of:
Due to the extra selectors, so we should be safe for the current implementation 👍 That being said, it's not 100% full-proof either. In certain scenarios, what if somehow your current older styles (below) is not stronger?
In that case, you may have to adjust the old/non CSS-in-JS styles a bit. In these cases, you'll have to adjust something either from the Emotion side, or the non emotion side. Having
|
👋Hallo!
This is a follow-up to the recently merged #17963 PR where we introduce CSS-in-JS into
@wordpress/components
via Emotion.Use case
The use case for this would be if we wanted to implement emotion React components into an older applications, with hostile pre-existing CSS rules (that probably won't/can't go away soon).
Example:
Instead of rendering the standard
.css-lkj1d9
class, it would renderhtml body .css-lkj1d9
.To combat things like legacy based
#id
CSS class names, something I did was add (or find) an#id
on html, and scope it likehtml#some-id body
.This resolved all integration based CSS specificity issues for me :).
Example/Solution
This was around the time Emotion v10 was being created. @mitchellhamilton created an example of this working with Emotion V10.
Here's the Codesandbox:
https://codesandbox.io/s/scopeprovider-and-frameprovider-qk1kg
I recently forked it, updated dependencies, and added comments.
The text was updated successfully, but these errors were encountered: