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

Do underlying shadow elements support class names and inline styles? #550

Closed
teddyfullstack opened this issue Apr 16, 2024 · 4 comments
Closed
Labels
enhancement New feature or request

Comments

@teddyfullstack
Copy link

Feature request

I want to justify my button content to the left, but the added class justify-left is put on the <vscode-button> element, which has no effect. I wonder how I can add the class to the underlying <button> element in the shadow root.

Expected behavior

Allow passing class names or inline styles to style the shadow elements.

Current behavior

Cannot style the button because the class names and inline styles are applied to the wrapper elements.

Use case

I'm trying to justify my button content to the left.

Screenshots/references

It would work if the class is passed to the actual <button> element instead:

Screenshot 2024-04-16 at 18 08 14
@teddyfullstack teddyfullstack added the enhancement New feature or request label Apr 16, 2024
@dinghar
Copy link

dinghar commented Jun 3, 2024

+1 I'm trying to disable the default blue outline of a textarea but am unable to accomplish this

@hawkticehurst
Copy link
Member

Hey @teddyfullstack! It's not well documented (apologies) but the part attribute/psuedo-element selector can be used to access/style elements within the shadow root.

You can read more about ::part() on MDN, but here's a basic example to give you an idea:

vscode-button::part(control) {
  background-color: red;
  /* insert other arbitrary styles */
}
vscode-button::part(control):hover {
  background-color: blue;
  /* insert other arbitrary styles */
}

Extra notes:

  • The part name "control" comes from FAST Foundation and is used widely across other components in the toolkit
  • There's no easy way to apply a class name to the elements in the shadow root thanks to how shadow DOM works and how FAST is built

@teddyfullstack
Copy link
Author

Wow, it worked like a charm. I learned something new, Thank you @hawkticehurst 🙏

@teddyfullstack
Copy link
Author

Anyone who uses tailwindcss, can add a matchVariant plugin like this:

const plugin = require("tailwindcss/plugin");

/** @type {import('tailwindcss').Config} */
module.exports = {
  plugins: [
    plugin(function ({ matchVariant }) {
      matchVariant("part", (value) => {
        return `&::part(${value})`;
      });
    }),
  ],
};

and then use it:

<VSCodeButton
    className="part-[control]:justify-start part-[content]:flex-1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants