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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
22 additions and
1 deletions
-
components/config-provider/DisabledContext.tsx
-
components/config-provider/__tests__/form.test.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> |
|
|
|
); |
|
|
|
|
|
@ -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(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|