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

Possibility to set all Material's CSS in a specific CSS layer #30512

Open
ositaka opened this issue Feb 18, 2025 · 0 comments
Open

Possibility to set all Material's CSS in a specific CSS layer #30512

ositaka opened this issue Feb 18, 2025 · 0 comments

Comments

@ositaka
Copy link

ositaka commented Feb 18, 2025

Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

Hello everyone,

After some research, I haven't found any way to assign the default Material components' injected CSS (from <style> tags) to a specific CSS layer (e.g., a layer named "material").

While I can configure a default Material CSS theme in a specific CSS layer, the inline styles injected by the components aren’t placed in that layer. This limitation forces me to rely on the !important keyword to override these styles, which isn’t ideal.

Is there a recommended approach or a potential enhancement to allow these inline styles to be assigned to a specific CSS layer by default?

Here’s an example for reference:

Image

Thank you for the help!

Proposed solution

Introduce a configuration option that allows developers to specify a CSS layer for the injected Material components' styles. Instead of inserting these styles without layer information, the library would wrap them in a <style> tag with the appropriate CSS layer attribute (e.g., layer="material"). This change would enable more predictable cascading behavior and simplify style overrides by eliminating the need for !important.

Alternatives considered

  • Overriding with !important: Currently, developers rely on using !important to override the default styles. However, this approach can lead to maintenance issues and unintended side effects.
  • Manual style injection: Developers could manually override or inject additional CSS rules after the default styles load, but this solution is error-prone and lacks scalability.
  • Custom style injection: Overriding the internal style injection mechanism might be possible, but this would be a hacky workaround that could break with future updates.
@JeanMeche JeanMeche transferred this issue from angular/angular Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant