-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
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
Modal confirm is in white color in dark theme #40576
Comments
None of the above links are helpful to the mentioned issue. |
@Khadhiri786 Hello, The App component should be used by wrapping your component like this. const MyApp: React.FC = () => (
<App>
<ButtonComponent/>
</App>
); |
@Yuiai01 I have tried, it's not working. Refer below codesandbox link |
|
@Khadhiri786 You can change the theme like I did. https://codesandbox.io/s/dark-theme-tmg8u9 |
@Khadhiri786 This link might help you, too. https://ant.design/components/app#sequence-with-configprovider 😁 |
I have the impression of having commented on a similar issue before, here. In the reproduction address you provided, I found two problems.
import { ConfigProvider, App } from "antd";
const root = createRoot(document.getElementById("root"));
root.render(
<ConfigProvider>
<App>{/** Use App.useApp here */}</App>
</ConfigProvider>
);
const My = () => {
const { message } = App.useApp();
return (
<Button
onClick={() => {
message.success("Clicked");
}}
>
Click Here
</Button>
);
}; Toggle full codeimport React from "react";
import { createRoot } from "react-dom/client";
import { ConfigProvider, theme, App, Button } from "antd";
import "antd/dist/reset.css";
import "./index.css";
const ButtonComponent = () => {
const { message } = App.useApp();
return (
<Button
onClick={() => {
message.success("Clicked");
}}
>
Click Here
</Button>
);
};
const root = createRoot(document.getElementById("root"));
root.render(
<div className="App">
<ConfigProvider
theme={{
algorithm: theme.darkAlgorithm,
}}
>
<App>
<ButtonComponent />
</App>
</ConfigProvider>
</div>
); Hope my answer can help you (I rely on translation software to communicate with you in |
@Wxh16144 do you have any idea about class component in react. |
I'm not familiar with class components, so I guess what you might want to know is how the HOC is handled. Here is a link |
We faced a similar issue with notifications. Cannot use the hooks everywhere as we use them in redux and react-query handlers as well. Figured we can have a component always rendered in App that will listen to messages sent through DOM events. Hope this helps someone. Should be easily tweaked to support modals or messages. NotificationHolder.tsx import { App } from 'antd';
import React from 'react';
import { NotificationDetail } from 'utils';
export function NotificationHolder(): null {
const { notification } = App.useApp();
React.useEffect(() => {
const handleMessage = ((event: CustomEvent<NotificationDetail>) => {
const { args, type } = event.detail;
notification[type](args);
}) as EventListener;
document.addEventListener('notificationEvent', handleMessage);
return () => {
document.removeEventListener('notificationEvent', handleMessage);
};
}, [notification]);
return null;
} utils/notification.ts import { ArgsProps, NotificationInstance } from 'antd/es/notification/interface';
export interface NotificationDetail {
type: 'success' | 'error' | 'warning' | 'info';
args: ArgsProps;
}
function getEvent(type: NotificationDetail['type'], args: ArgsProps) {
return new CustomEvent<NotificationDetail>('notificationEvent', {
detail: {
type,
args,
},
});
}
export const notification: Omit<NotificationInstance, 'open' | 'destroy'> = {
info: (args: ArgsProps) => {
document.dispatchEvent(getEvent('info', args));
},
error: (args: ArgsProps) => {
document.dispatchEvent(getEvent('error', args));
},
success: (args: ArgsProps) => {
document.dispatchEvent(getEvent('success', args));
},
warning: (args: ArgsProps) => {
document.dispatchEvent(getEvent('warning', args));
},
}; Your App.tsx import { App } from 'antd';
import { NotificationHolder } from 'components';
<App>
<NotificationHolder />
</App> Anywhere else import { notification } from 'utils';
notification.success({ message: 'Operation successful.' }) |
Duplicate of #40546 |
Reproduction link
Steps to reproduce
#38671 (comment)
What is expected?
Modal, Notification and Message popups should display with black background in dark mode.
What is actually happening?
These popup's background is displaying with white background in dark theme. If we use hooks from
App
we are getting error message as shown below.Screenshots:
The text was updated successfully, but these errors were encountered: