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

CSS variables should be scoped #14678

Open
Ocean-OS opened this issue Dec 11, 2024 · 6 comments
Open

CSS variables should be scoped #14678

Ocean-OS opened this issue Dec 11, 2024 · 6 comments

Comments

@Ocean-OS
Copy link
Contributor

Describe the bug

When using CSS variables, they are not scoped correctly. Their names should have the component's CSS hash appended to it to avoid scoping issues.

Reproduction

REPL

Logs

No response

System Info

N/A

Severity

annoyance

@Ocean-OS Ocean-OS changed the title Bug: CSS variables should be scoped CSS variables should be scoped Dec 11, 2024
@webJose
Copy link
Contributor

webJose commented Dec 11, 2024

This probably breaks more than one thing. For instance my @wjfe/dataview component, which is styled by defining CSS variables. Is there a specific case you have in mind where this is needed? What would be the way to use them unscoped? Like in here:

.some-class {
  background-color: rgba(var(--bs-bg-color-rgb), var(--bs-bg-opacity));
}

I suppose that those would be rendered as:

.some-class {
  background-color: rgba(var(--bs-bg-color-rgb-HASH), var(--bs-bg-opacity-HASH));
}

Then what syntax would be feasible to make them global?

.some-class {
  background-color: rgba(var(:global(--bs-bg-color-rgb)), var(:global(--bs-bg-opacity)));
}

Like that, maybe? I'm not sure if I like this or not. I'm on the fence. If I were the one writing the parsing code, I would hate it, though. 😄

@7nik
Copy link

7nik commented Dec 11, 2024

I never needed it, and even the opposite, I have written code that relies on the fact that CSS variables keep their names - I used them to adjust some styling in child components.

@Conduitry
Copy link
Member

This sounds like a bad idea. CSS vars shouldn't be scoped any more than component props should be scoped.

@Ocean-OS
Copy link
Contributor Author

This probably breaks more than one thing. For instance my @wjfe/dataview component, which is styled by defining CSS variables. Is there a specific case you have in mind where this is needed? What would be the way to use them unscoped? Like in here:

.some-class {
  background-color: rgba(var(--bs-bg-color-rgb), var(--bs-bg-opacity));
}

I suppose that those would be rendered as:

.some-class {
  background-color: rgba(var(--bs-bg-color-rgb-HASH), var(--bs-bg-opacity-HASH));
}

Then what syntax would be feasible to make them global?

.some-class {
  background-color: rgba(var(:global(--bs-bg-color-rgb)), var(:global(--bs-bg-opacity)));
}

Like that, maybe? I'm not sure if I like this or not. I'm on the fence. If I were the one writing the parsing code, I would hate it, though. 😄

Maybe instead of automatically scoping, there was a :scope()/scope() function that scoped the variable, and otherwise the variable is globally scoped?

@Thiagolino8
Copy link

The main use for CSS variables is dependency injection, making them scoped destroys this use
CSS variables are not like scss variables

@Thiagolino8
Copy link

But I think it's possible to argue the case for variables declared with @Property specifically, and make them global when declared inside a :global{} block.

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

5 participants