Skip to content

Commit

Permalink
bugfix(DisabledContextProvider): fix disabled logic (#38886)
Browse files Browse the repository at this point in the history
* bugfix(DisabledContextProvider): fix disabled logic

* test: add test for ConfigProvider componentDisabled

Co-authored-by: dian.li <dian.li@yunzhanghu.com>
  • Loading branch information
2 people authored and MadCcc committed Nov 23, 2022
1 parent ea6a801 commit 8907c39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/config-provider/DisabledContext.tsx
Expand Up @@ -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>
);
Expand Down
21 changes: 21 additions & 0 deletions components/config-provider/__tests__/form.test.tsx
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit 8907c39

Please sign in to comment.