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

New ant design version 5.0.0 is confilicting with tailwindcss #38794

Closed
rizwan92 opened this issue Nov 21, 2022 · 71 comments
Closed

New ant design version 5.0.0 is confilicting with tailwindcss #38794

rizwan92 opened this issue Nov 21, 2022 · 71 comments
Labels
❓FAQ issues would be discussed a lot

Comments

@rizwan92
Copy link

rizwan92 commented Nov 21, 2022

Reproduction link

code sandbox reproduction

Steps to reproduce

<Button type="primary> Button button primary is not working

What is expected?

Button primary should work

What is actually happening?

Button Primary is not right output

Environment Info
antd 5.0.0
React 18
System mac os
Browser chrome

please fix it

@MadCcc MadCcc added the 🤔 Need Reproduce We cannot reproduce your problem label Nov 21, 2022
@github-actions
Copy link
Contributor

Hello @rizwan92. Please provide a online reproduction by forking codesandbox of antd@5.x or antd@4.x, or provide a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 3 days.

你好 @rizwan92, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击这里创建一个 antd@5.xantd@4.x 的 codesandbox,或者提供一个最小化的 GitHub 仓库。3 天内未跟进此 issue 将会被自动关闭。

@rizwan92
Copy link
Author

reproduction link added

@li-jia-nan

This comment was marked as outdated.

@MadCcc MadCcc removed the 🤔 Need Reproduce We cannot reproduce your problem label Nov 21, 2022
@sherali-1
Copy link

sherali-1 commented Nov 21, 2022

yes @li-jia-nan's solution is working for me previous version and after migrating to new 5.0 version still working

@MadCcc
Copy link
Member

MadCcc commented Nov 22, 2022

It's not issue with antd since tailwindcss's preflight override the style of Button. The priority of css selector are the same.

@MadCcc MadCcc closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2022
@rizwan92
Copy link
Author

rizwan92 commented Nov 22, 2022

@li-jia-nan preflight: false tailwind border not working and may more feature not working in tailwind

and one more thing as you can see my primary colour is different in the antd config provider in the reproduction link but form input element has blue border color when we focus on it

@Damienbelingheri
Copy link

@li-jia-nan preflight: false tailwind border not working and may more feature not working in tailwind

and one more thing as you can see my primary colour is different in the antd config provider in the reproduction link but form input element has blue border color when we focus on it

Same problem here ! Can you please reopen the issue @MadCcc ?

@li-jia-nan li-jia-nan reopened this Nov 24, 2022
@li-jia-nan
Copy link
Member

reopen

@phatify
Copy link

phatify commented Nov 27, 2022

facing the same issue

@phatify
Copy link

phatify commented Nov 27, 2022

reopen

@li-jia-nan we need a patched update soon!

@phatify
Copy link

phatify commented Nov 27, 2022

Ohhh! I fixed this issue by using StyleProvider, it work like a charm:

<ConfigProvider
  theme={{
    token: {
      colorPrimary: "#000",
    },
  }}
>
  <StyleProvider hashPriority="high">
    <RootApp />
  </StyleProvider>
</ConfigProvider>

My Reproduction link demo:
https://stackblitz.com/edit/nextjs-6j8zb7?file=pages/_app.js

@MadCcc
Copy link
Member

MadCcc commented Nov 27, 2022

Ohhh! I fixed this issue by using StyleProvider, it work like a charm:

<StyleProvider hashPriority="high">
    <RootApp />
</StyleProvider>

Yes, this could help solve the problem by raise the priority of antd's selector. Since we do not have better solution for mixed style with tailwindcss, this may be the most suitable way to fix it. But you should be aware of the high priority brought by hash class, it may cause some other effect in style. Ref: https://ant.design/docs/react/customize-theme#compatible-adjustment

Going to close this issue with possible solution. Feel free to open new issue if encounter with other problems.

@MadCcc MadCcc closed this as completed Nov 27, 2022
@zombieJ
Copy link
Member

zombieJ commented Nov 27, 2022

Though the StyleProvider with hashPriority="high" is design for legacy browser. But it seems also resolve this problem:
https://ant.design/docs/react/customize-theme#compatible-adjustment

@Vincz
Copy link

Vincz commented Dec 9, 2022

The StyleProvider solution was working a couple of days ago, but it doesn't seems to work anymore.

@yf-hk
Copy link

yf-hk commented Dec 11, 2022

Any updates?

@chunsch
Copy link
Contributor

chunsch commented Dec 11, 2022

One way is to configuration Important of Tailwind CSS, let Tailwind CSS a higher priority.

// tailwind.config.js

module.exports = {
// ...other

  corePlugins: {
// Remove Tailwind CSS's preflight style so it can use the antd's preflight instead (reset.css).
    preflight: false
  },
  important: '#app',

// ...other
}
// pages/_document.tsx or app/layout.tsx

<body id="app">
...
</body>
/* globals.css */

@import 'antd/dist/reset.css';

// fix Tailwind CSS border styles,form Tailwind CSS's preflight
*,
::before,
::after {
  box-sizing: border-box; /* 1 */
  border-width: 0; /* 2 */
  border-style: solid; /* 2 */
  border-color: theme('borderColor.DEFAULT', currentColor); /* 2 */
}

::before,
::after {
  --tw-content: '';
}

@tailwind base;
@tailwind components;
@tailwind utilities;

@KhokharJunaid
Copy link

You can close preflight in tailwind.config.cjs:

// tailwind.config.cjs
module.exports = {
  corePlugins: {
    preflight: false,
  },
};

Thanks, bro it is really working for me.

@phatify
Copy link

phatify commented Dec 19, 2022

The StyleProvider solution was working a couple of days ago, but it doesn't seems to work anymore.

@Vincz what's going on with you ?

@phatify
Copy link

phatify commented Dec 19, 2022

You can close preflight in tailwind.config.cjs:

// tailwind.config.cjs
module.exports = {
  corePlugins: {
    preflight: false,
  },
};

Thanks, bro it is really working for me.

@KhokharJunaid keep in mind that disabling preflight is not a good idea, because you must be re-develop base styles global when preflight disabled.
If preflight is disabled, you will have to write more className (e.g: border-solid, divider, ... ) and more customize.

@gavinliu6
Copy link

<StyleProvider hashPriority="high">...</StyleProvider> doesn't work now.

@phatify
Copy link

phatify commented Dec 22, 2022

<StyleProvider hashPriority="high">...</StyleProvider> doesn't work now.

doesn't work? can you give me reproduction link?

@zombieJ
Copy link
Member

zombieJ commented Dec 22, 2022

Hi, pls confirm with @ant-design/cssinjs version which should match with antd used.

@zombieJ zombieJ added the ❓FAQ issues would be discussed a lot label Dec 22, 2022
@Time1sMoney
Copy link

So is there an optimal solution? i use antd@5.7.2 and tailwindcss@3.3.2👀

@yunsii
Copy link

yunsii commented Aug 19, 2023

I have made a postcss plugin postcss-antd-fixes tries to process conflicts of antd with any others global CSS reset, support TailwindCSS for now. Online example: https://stackblitz.com/edit/postcss-antd-fixes?file=postcss.config.js


20230924 Update

I just found that there is also a anchor style conflict, antd will generate link style like this
image

And tailwind has related anchor reset css: https://github.com/tailwindlabs/tailwindcss/blob/b33c30284f8a857a94c5dece88d489a7589dfaf6/src/css/preflight.css#L88

a {
  color: inherit;
  text-decoration: inherit;
}

So I add new fix function to resolve it, make anchors style under any antd components normal as expected, online example updated.

@zanniboni
Copy link

any updates on this issue?

1 similar comment
@FeiPengDev
Copy link

any updates on this issue?

@yunsii
Copy link

yunsii commented Sep 24, 2023

I have made a postcss plugin postcss-antd-fixes tries to process conflicts of antd with any others global CSS reset, support TailwindCSS for now. Online example: stackblitz.com/edit/postcss-antd-fixes?file=postcss.config.js

20230924 Update

I just found that there is also a anchor style conflict, antd will generate link style like this image

And tailwind has related anchor reset css: tailwindlabs/tailwindcss@b33c302/src/css/preflight.css#L88

a {
  color: inherit;
  text-decoration: inherit;
}

So I add new fix function to resolve it, make anchors style under any antd components normal as expected, online example updated.

FYI, There is a anchor style conflict to be fixed.

@EdwardMoMo
Copy link

I have made a postcss plugin postcss-antd-fixes tries to process conflicts of antd with any others global CSS reset, support TailwindCSS for now. Online example: stackblitz.com/edit/postcss-antd-fixes?file=postcss.config.js

20230924 Update

I just found that there is also a anchor style confilict, antd will generate link style like this image
And tailwind has related anchor reset css: tailwindlabs/tailwindcss@b33c302/src/css/preflight.css#L88

a {
  color: inherit;
  text-decoration: inherit;
}

So I add new fix function to resolve it, make anchors style under any antd components normal as expected, online example updated.

FYI, There is a anchor style conflict to be fixed.

Hi, @yunsii May I know if you fixed this anchor style conflict?

@yunsii
Copy link

yunsii commented Oct 5, 2023

@EdwardMoMo As a non-native English speaker, maybe my expression is not clear? I had fixed and released with postcss-antd-fixes@0.2.0

@EdwardMoMo
Copy link

Great, thanks, I noticed the new commit of your plugin.

@dananjaya6005
Copy link

guys

Ohhh! I fixed this issue by using StyleProvider, it work like a charm:

<ConfigProvider
    theme={{
        token: {
            colorPrimary: '#000000',
        },
    }}
>
    <StyleProvider hashPriority="high">
        <RootApp />
    </StyleProvider>
</ConfigProvider>

My Reproduction link demo: https://stackblitz.com/edit/nextjs-6j8zb7?file=pages/_app.js

this one is working perfectly. no need to disable tailwindcss's preflight. Also, disabling preflight is not recommended.It can be affect to native tailwind style

@BarrySong97
Copy link

Ohhh! I fixed this issue by using StyleProvider, it work like a charm:

<ConfigProvider
    theme={{
        token: {
            colorPrimary: '#000000',
        },
    }}
>
    <StyleProvider hashPriority="high">
        <RootApp />
    </StyleProvider>
</ConfigProvider>

My Reproduction link demo: https://stackblitz.com/edit/nextjs-6j8zb7?file=pages/_app.js

This worked for me well.

@kaustubhxd
Copy link

I gave up after trying everything for fixing my button color. I went with this in global.css

.ant-btn-primary { background-color: #1677ff !important; }

@jagaa999
Copy link

I gave up after trying everything for fixing my button color. I went with this in global.css

.ant-btn-primary { background-color: #1677ff !important; }

maybe me too

@jagaa999
Copy link

I have made a postcss plugin postcss-antd-fixes tries to process conflicts of antd with any others global CSS reset, support TailwindCSS for now. Online example: https://stackblitz.com/edit/postcss-antd-fixes?file=postcss.config.js

20230924 Update

I just found that there is also a anchor style conflict, antd will generate link style like this image

And tailwind has related anchor reset css: https://github.com/tailwindlabs/tailwindcss/blob/b33c30284f8a857a94c5dece88d489a7589dfaf6/src/css/preflight.css#L88

a {
  color: inherit;
  text-decoration: inherit;
}

So I add new fix function to resolve it, make anchors style under any antd components normal as expected, online example updated.

Thank you, it is working for me. Saving my life.

@abduhere
Copy link

abduhere commented Jul 4, 2024

While going through this thread and exploring different options to configure Tailwind CSS with AntD V5, I finally found the official solution on the AntD website.
Link to solution: https://ant.design/docs/react/compatible-style#tailwindcss-arrange-layer

This solution of AntD website worked best for me. Hope this helps other people too!

@yunsii
Copy link

yunsii commented Jul 4, 2024

Also I have updated my postcss plugin docs: https://github.com/yunsii/postcss-antd-fixes#features

@muyoou
Copy link

muyoou commented Jul 30, 2024

While going through this thread and exploring different options to configure Tailwind CSS with AntD V5, I finally found the official solution on the AntD website. Link to solution: https://ant.design/docs/react/compatible-style#tailwindcss-arrange-layer

This solution of AntD website worked best for me. Hope this helps other people too!

It is working perfectly for me, thank you!

@anotheri
Copy link

anotheri commented Feb 5, 2025

Does anybody have a luck to make it work with Tailwind CSS 4 (+ lightning css, ideally)?

@liaoyinglong
Copy link
Contributor

@anotheri try replace @import "tailwindcss"; with following

@layer theme, base, components, utilities;

@import 'tailwindcss/theme.css' layer(theme);
@import 'tailwindcss/preflight.css' layer(base);

// put @tailwind utilities in #app or other selectors
#app {
  @tailwind utilities;
}

then u can see it works

<Button className='hidden'>start</Button>

@diqye
Copy link

diqye commented Feb 23, 2025

root.render(<ConfigProvider theme={theme}><StyleProvider hashPriority="high"><UI /></StyleProvider></ConfigProvider>);
works for me.

@anotheri
Copy link

@liaoyinglong yeah, i've also noticed last week that it seems to be working as expected (after a couple updates of Vite, postcss so most probably it was not directly related to antd), thanks for heads up anyways.

zollero added a commit to zollero/umi that referenced this issue Mar 15, 2025
Refer to [the doc file](https://ant.design/docs/react/compatible-style#tailwindcss-arrange-layer) of Antd, the `tailwind.css` file content need some modifies.

The related issue of antd for refrerence. ant-design/ant-design#38794 (comment)
@revskill10
Copy link

Can you put a working stackblitz example @diqye @anotheri ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓FAQ issues would be discussed a lot
Projects
None yet
Development

No branches or pull requests