Skip to content

CSS scoping deep combinators #24289

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

Merged
merged 2 commits into from
Jul 24, 2020
Merged

Conversation

SteveSandersonMS
Copy link
Member

This is needed to make CSS scoping useful when you're trying to style elements produced by descendants. It's equivalent to deep selectors in Vue.

For example, we want to use this in the template to style the <a> tags emitted by NavLink.

cc @javiercn who has context on this

@SteveSandersonMS SteveSandersonMS added the area-blazor Includes: Blazor, Razor Components label Jul 24, 2020
@SteveSandersonMS SteveSandersonMS requested a review from a team July 24, 2020 17:35
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 24, 2020
@SteveSandersonMS
Copy link
Member Author

Note: the diff in the implementation is really noisy and makes it look like I changed more than I did. It's because previously the only kind of "edit" done in the CSS rewriter was "insertion", and I had to generalise this to support "deletion" too, which means that all the names that included "insert" were no longer applicable and I had to rename them all it "edit" instead.

{
// ::deep is a convenient and friendly syntax
// ::razor-deep is an alias the people can use if they are concerned about possible clashes with other meanings
return string.Equals(simpleSelectorText, "::deep", StringComparison.Ordinal)
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

@SteveSandersonMS SteveSandersonMS Jul 24, 2020

Choose a reason for hiding this comment

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

Note, I removed ::razor-deep because I realised it doesn't make any sense. These tokens are already stripped out by the time the CSS reaches the browser, so it's not possible to clash against anything in the browser. The place you could clash is if you wanted the token not to be interpreted as a deep combinator by our rewriter (because you did want it to reach the browser). But adding more aliases doesn't give you any way to do that, so it was pointless.

In the future we could expose some option for what the combinator text is, but there's no requirement for that today.

@@ -75,6 +75,40 @@ public void HandlesSpacesAndCommentsWithinSelectors()
", result);
}

[Fact]
public void RespectsDeepCombinator()
Copy link
Member

Choose a reason for hiding this comment

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

It will be interesting to have a case with multiple instances of ::deep, something like .a ::deep .b ::deep .c

Copy link
Member Author

Choose a reason for hiding this comment

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

Added test

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

Looks great!

@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/css-scoping-deep branch from b81be91 to 18f6f17 Compare July 24, 2020 17:50
@SteveSandersonMS
Copy link
Member Author

@mkArtakMSFT Can you merge this once the tests pass? It's for preview 8.

@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/css-scoping-deep branch from 18f6f17 to 81b25e4 Compare July 24, 2020 18:18
@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/css-scoping-deep branch from 81b25e4 to 9ae93d2 Compare July 24, 2020 18:40
@pranavkm pranavkm added this to the 5.0.0-preview8 milestone Jul 24, 2020
@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/css-scoping-deep branch from 3257eff to 2747e54 Compare July 24, 2020 20:12
@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/css-scoping-deep branch from 2747e54 to aab15cc Compare July 24, 2020 20:22
@mkArtakMSFT mkArtakMSFT merged commit eb8764e into release/5.0-preview8 Jul 24, 2020
@mkArtakMSFT mkArtakMSFT deleted the stevesa/css-scoping-deep branch July 24, 2020 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants