mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
bugfix(DisabledContextProvider): fix disabled logic (#38886)
* bugfix(DisabledContextProvider): fix disabled logic * test: add test for ConfigProvider componentDisabled Co-authored-by: dian.li <dian.li@yunzhanghu.com>
This commit is contained in:
parent
ea6a801290
commit
8907c3910f
@ -12,7 +12,7 @@ export interface DisabledContextProps {
|
||||
export const DisabledContextProvider: React.FC<DisabledContextProps> = ({ children, disabled }) => {
|
||||
const originDisabled = React.useContext(DisabledContext);
|
||||
return (
|
||||
<DisabledContext.Provider value={disabled || originDisabled}>
|
||||
<DisabledContext.Provider value={disabled ?? originDisabled}>
|
||||
{children}
|
||||
</DisabledContext.Provider>
|
||||
);
|
||||
|
@ -4,6 +4,7 @@ import ConfigProvider from '..';
|
||||
import { render } from '../../../tests/utils';
|
||||
import type { FormInstance } from '../../form';
|
||||
import Form from '../../form';
|
||||
import Input from '../../input';
|
||||
import zhCN from '../../locale/zh_CN';
|
||||
|
||||
describe('ConfigProvider.Form', () => {
|
||||
@ -125,4 +126,24 @@ describe('ConfigProvider.Form', () => {
|
||||
expect(container.querySelector('.ant-form-item-no-colon')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('form disabled', () => {
|
||||
it('set Input enabled', () => {
|
||||
const { container } = render(
|
||||
<Form disabled>
|
||||
<ConfigProvider componentDisabled={false}>
|
||||
<Form.Item name="input1" label="启用">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</ConfigProvider>
|
||||
<Form.Item name="input" label="禁用">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Form>,
|
||||
);
|
||||
|
||||
expect(container.querySelector('#input1[disabled]')).toBeFalsy();
|
||||
expect(container.querySelector('#input[disabled]')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user