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

Unable to use native styles to style elements contained in a web component #173

Open
lloydk opened this issue Feb 2, 2025 · 2 comments
Open
Labels
bug Something isn't working

Comments

@lloydk
Copy link

lloydk commented Feb 2, 2025

Describe the bug

I was trying to use the native styles in a web component that contained some native elements but was unable to get the native elements to style properly. It looks like some of the styles are being applied to the host element?

Demo

Here is a link to a lit playground that demonstrates the problem:

https://lit.dev/playground/#sample=examples%2Fhello-world&gist=67b7c8576c5b994ffc8ec9242f0825a3

Screenshots

All screenshots from Chrome 132.0.6834.161 on Windows 10

Image

With radio.css included last:

Image

With just native.css imported:

Image

@lloydk lloydk added the bug Something isn't working label Feb 2, 2025
@claviska
Copy link
Member

claviska commented Feb 3, 2025

It looks like the imports are missing the version. Try this.

@import url('https://early.webawesome.com/[email protected]/dist/styles/native/forms.css');
@import url('https://early.webawesome.com/[email protected]/dist/styles/native/input.css');
@import url('https://early.webawesome.com/[email protected]/dist/styles/native/select.css');

The styles appear to be loading for the respective controls using those imports.

@lloydk
Copy link
Author

lloydk commented Feb 3, 2025

The styles are loading with the existing urls (those are the urls you get when you edit an example in the docs). I can change them but I don't see how it will make a difference.

If you go into dev tools and select the simple-greeting element you can see that it's picking up the web awesome style which is causing the problems in the example images above.

Image

With radio.css included I get a border on simple-greeting (in Chrome but not Firefox) and if I uncheck the border-style property the border goes away.

radio.css has a :host selector for some of the styles so the display property of simple-greeting becomes inline-flex. That's why the layout changes in the example images when radio.css is included.

Image

Just for completeness, selecting an input element in the dev tools also shows that at least some of the styles are being applied to the input element.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants