Reproduction link
Steps to reproduce
Run the reproduction app. Inspect styling of the "This child is placed in the document body." element that is teleported to the body.
What is expected?
Element teleported to the body should inherit styling from antd theme.
What is actually happening?
Teleported element is not inheriting styles, as styles are only applied starting from Layout antd component, which is inside the body and container element, where app is rendered.
In previous version body was styled using those less variables:
body {
color: @text-color;
font-size: @font-size-base;
font-family: @font-family;
font-variant: @font-variant-base;
line-height: @line-height-base;
background-color: @body-background; // 2
font-feature-settings: @font-feature-settings-base;
}
Now it is not happening, since antd V5 uses css-in-js.
Environment | Info |
---|---|
antd | 5.19.1 |
React | 17.0.2 |
System | macOS Sonoma 14.5 |
Browser | Google Chrome Version 126.0.6478.127 (Official Build) (arm64) |
- I know this philosophy to make body being styled with theme variables contradicts to using css-in-js, but maybe you have some idea how can we go around it? Probably use the same variable in theme and in body styles. But I think this is a general issue, as it is often needed to teleport stuff to body to be properly displayed.
- I noticed, that in the reset.css you do not provide font family for body, but you provide monospace font family for monospace html tags. Why? What if someone change fontFamilyCode in the theme - that won't be reflected in the reset.css?
5条答案
按热度按时间xlpyo6sf1#
Start a new pull request in StackBlitz Codeflow .
yizd12fk2#
In v4 or prev version, there exist lots complain about
antd.css
reset user style even when they only use part of antd component. So we extract the global style into 2 part:If you want to have the default font style, you can consider to wrap the App component at the top which will help to align with antd style : )
i34xakig3#
Will App component modify body style?
2guxujil4#
Like what if I have a component that is teleported to the body to be displayed, like a tooltip or dialog. Then App component doesn't help me at all.
And reset.css is missing couple of styles from previous version. And I guess it won't be possible for it to have proper font set up, because it is now set in js.
For now I have injected Antd variables into our less files and style the body as it used to be. But I guess this is not a perfect solution?
p4tfgftt5#
Same question. Why antd@5 ignore the body's font and base font-weight? This is outrageous