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

[Feature]: v9 FluentProvider has no way to apply dark theme to body #23626

Open
1 task done
dzearing opened this issue Jun 21, 2022 · 4 comments · May be fixed by #33632
Open
1 task done

[Feature]: v9 FluentProvider has no way to apply dark theme to body #23626

dzearing opened this issue Jun 21, 2022 · 4 comments · May be fixed by #33632

Comments

@dzearing
Copy link
Member

dzearing commented Jun 21, 2022

Library

React Components / v9 (@fluentui/react-components)

Describe the feature that you would like added

When we build web apps which use dark theme, body needs to be dark themed, with the right default bg/fg colors, as well font family/size/weight. We need FluentProvider to apply the theme props to the body element on demand.

In v8 and prior, we had a prop called applyTo which allowed the theme to be targeted at the body element. This was how the root provider could apply the theme to the full app. (The default behavior would still be contained, however.)

It would be great to just have this prop as well in v9. It would simplify transitioning to the new provider, and solve a major issue with v9.

Have you discussed this feature with our team

Discussed with a few people who didn't know.

Additional context

I found this using the theme provider. I exported a dark mode example. Most of the example page was light colored, which feels pretty busted. Nobody wants a half dark mode app.

Validations

  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@dzearing
Copy link
Member Author

dzearing commented Jun 21, 2022

@layershifter provided this workaround:

import {
  teamsDarkTheme,
  FluentProvider,
  useThemeClassName
} from "@fluentui/react-components";
import * as React from "react";

function ApplyToBody() {
  const classes = useThemeClassName();

  React.useEffect(() => {
    const classList = classes.split(" ");
    document.body.classList.add(...classList);

    return () => document.body.classList.remove(...classList);
  }, [classes]);

  return null;
}

export const Default = () => {
  return (
    <FluentProvider theme={teamsDarkTheme}>
      <ApplyToBody />
      <div>Hello world</div>
    </FluentProvider>
  );
};

It's good to have a workaround but this will be unobvious to customers. They'll need to do this every time they build a new app and need to apply the theme class to body. Options:

  • Ergonomic and upgrade friendly: add applyTo prop, makes transitioning easier.
  • Acceptable, but not user-friendly: Ship ApplyToBody component in fluent and document it.
  • Messy: suggest apps call useThemeClassName. It shouldn't be exported; less surface = less breaks, less documentation requirements.

@dzearing
Copy link
Member Author

dzearing commented Jun 22, 2022

I believe MUI uses something similar to option 2:

https://mui.com/material-ui/react-css-baseline/

return (
    <ThemeProvider theme={theme}>
      <CssBaseline />
      <h1>Grey h1 element</h1>
    </ThemeProvider>
  );

Which is acceptable, it has the benefit of compartmentalizing the logic of applying the baseline css to a separate component, but just requires someone look up what to do on stack overflow.

Having a dedicated prop applyTo="body" on FluentProvider would be a cheap solution and most ergonomic and discoverable for customers.

@msft-fluent-ui-bot
Copy link
Collaborator

Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

@msft-fluent-ui-bot msft-fluent-ui-bot added the Resolution: Soft Close Soft closing inactive issues over a certain period label Mar 23, 2023
@microsoft microsoft locked as resolved and limited conversation to collaborators Apr 22, 2023
@dzearing dzearing reopened this May 5, 2023
@dzearing
Copy link
Member Author

dzearing commented May 5, 2023

Boo, soft close. Should be addressed.

@khmakoto khmakoto reopened this Oct 2, 2023
@khmakoto khmakoto removed the Resolution: Soft Close Soft closing inactive issues over a certain period label Oct 2, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution: Soft Close Soft closing inactive issues over a certain period label Feb 29, 2024
@tudorpopams tudorpopams reopened this Jan 11, 2025
@tudorpopams tudorpopams added Partner Ask and removed Resolution: Soft Close Soft closing inactive issues over a certain period labels Jan 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.