-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Comments
@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:
|
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 |
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. |
Boo, soft close. Should be addressed. |
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
The text was updated successfully, but these errors were encountered: