mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 09:39:10 +08:00
8907c3910f
* bugfix(DisabledContextProvider): fix disabled logic * test: add test for ConfigProvider componentDisabled Co-authored-by: dian.li <dian.li@yunzhanghu.com>
22 lines
582 B
TypeScript
22 lines
582 B
TypeScript
import * as React from 'react';
|
|
|
|
export type DisabledType = true | false | undefined;
|
|
|
|
const DisabledContext = React.createContext<DisabledType>(false);
|
|
|
|
export interface DisabledContextProps {
|
|
disabled?: DisabledType;
|
|
children?: React.ReactNode;
|
|
}
|
|
|
|
export const DisabledContextProvider: React.FC<DisabledContextProps> = ({ children, disabled }) => {
|
|
const originDisabled = React.useContext(DisabledContext);
|
|
return (
|
|
<DisabledContext.Provider value={disabled ?? originDisabled}>
|
|
{children}
|
|
</DisabledContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default DisabledContext;
|