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

Some style properties are lost on Native federation application #2903

Open
kasar-NTT opened this issue May 24, 2024 · 7 comments
Open

Some style properties are lost on Native federation application #2903

kasar-NTT opened this issue May 24, 2024 · 7 comments

Comments

@kasar-NTT
Copy link

kasar-NTT commented May 24, 2024

Detailed description

Describe in detail the issue you're having.
Issue on setting up the @carbon/styles on a native federation micro frontend. While developing the MFE application as a standalone, everything works as expected. But when it's time to fetch my MFE from a host application then some style properties are lost

Is this a feature request (new component, new icon), a bug, or a general issue?
Bug

Is this issue related to a specific component?
No

What did you expect to happen? What happened instead? What would you like to see changed?
I would expect the MFE application to work as expected both as a standalone or hosted inside another application

What browser are you working in?
Chrome

What version of the Carbon Design System are you using?
"@carbon/styles": "^1.57.0",
"carbon-components-angular": "^5.25.1",

Additional information

  • Screenshots or code
    As seen in the below screenshot, the button with a download icon is broken.
    On the right side, you can see that the: --cds-layout-size-height-local among with others are undefined
    image

Also, it mentions that it inherits the styles from app-root, instead of the @carbon related styles
image

While working on the MFE as a standalone, everything works as expected:
image

and the properties are inherited correctly:

image

@Akshat55
Copy link
Contributor

@kasar-NTT, styles are isolated in shadow-root and majority of the styles cannot be inherited from the root. This includes css variables, hence the undefined. I see that the root is open, have you passed in a styles sheet that imports carbon styles?

The following mdn docs may be useful to adding style to the shadow root:

@kasar-NTT
Copy link
Author

@Akshat55 you are right, in my MFE application i have set the encapsulation to ShadowDom.
I have imported to the styles.scss the: @import "@carbon/styles/scss/components/button" and also in my specific component that is visible in the screenshot as well. I tried also with: @import "@carbon/styles and adding the fonts path that is required for that kind of import, but no luck

@Akshat55
Copy link
Contributor

Have you tried setting the theme in the html for the MFE? Carbon v5 makes use of css variables and you can set these variables by importing the theme in the root as following:

@include styles.theme(styles.$white);

@kasar-NTT
Copy link
Author

I will try that and come back for feedback! Thanks @Akshat55

@kasar-NTT
Copy link
Author

kasar-NTT commented Jul 12, 2024

Update,

the only to manage having the styles available on my components is by importing the required scss of the carbon component i want to use.

For example if i need to use the carbon dropdown i need to import into my-component.scss ->
@import "@carbon/styles/scss/components/dropdown/index";

This is the way i manage to get the required styles

@Akshat55
Copy link
Contributor

Thank you for updating the issue and posting your solution!

It's odd that you would have to import individual component styling. I'm not 100% sure if this is possible, but can't you just create a global stylesheet with the following code in your assets directory and inject it into shadow root?

    // general stylesheet to inject
    @use '@carbon/styles';
    body { // Body or component tag?
     @include styles.theme(styles.$white); 
    }

@kasar-NTT
Copy link
Author

When adding the @carbon/styles it requires to have the fonts locally.
Is this normal?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants