Browse Source

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>
pull/38913/head
dainli 2 years ago
committed by GitHub
parent
commit
6f4b96567b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/config-provider/DisabledContext.tsx
  2. 21
      components/config-provider/__tests__/form.test.tsx

2
components/config-provider/DisabledContext.tsx

@ -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>
);

21
components/config-provider/__tests__/form.test.tsx

@ -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…
Cancel
Save