mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
refactor: improve the acquisition of dom logic (#48989)
* deps: bump rc-util to 5.41.0 * refactor: improve the acquisition of dom logic * test: add unit test
This commit is contained in:
parent
35015c7b4f
commit
baef247630
@ -559,6 +559,26 @@ describe('Form', () => {
|
||||
expect(scrollIntoView).toHaveBeenCalled();
|
||||
expect((scrollIntoView as any).mock.calls[0][0]).toBe(uploadRef.current.nativeElement);
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/48981
|
||||
it('should not throw error when use InputNumber', async () => {
|
||||
const inputNumberRef = React.createRef<any>();
|
||||
|
||||
const { getByText } = render(
|
||||
<Form scrollToFirstError>
|
||||
<Form.Item name="demo-form_input-number" rules={[{ required: true }]}>
|
||||
<InputNumber ref={inputNumberRef} />
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button htmlType="submit">Submit</Button>
|
||||
</Form.Item>
|
||||
</Form>,
|
||||
);
|
||||
fireEvent.click(getByText('Submit'));
|
||||
await waitFakeTimer();
|
||||
expect(scrollIntoView).toHaveBeenCalled();
|
||||
expect((scrollIntoView as any).mock.calls[0][0]).toBe(inputNumberRef.current?.nativeElement);
|
||||
});
|
||||
});
|
||||
|
||||
it('Form.Item should support data-*、aria-* and custom attribute', () => {
|
||||
|
@ -2,6 +2,7 @@ import * as React from 'react';
|
||||
import type { FormInstance as RcFormInstance } from 'rc-field-form';
|
||||
import { useForm as useRcForm } from 'rc-field-form';
|
||||
import scrollIntoView from 'scroll-into-view-if-needed';
|
||||
import { getDOM } from 'rc-util/lib/Dom/findDOMNode';
|
||||
|
||||
import type { InternalNamePath, NamePath, ScrollOptions } from '../interface';
|
||||
import { getFieldId, toArray } from '../util';
|
||||
@ -25,13 +26,10 @@ function toNamePathStr(name: NamePath) {
|
||||
|
||||
function getFieldDOMNode(name: NamePath, wrapForm: FormInstance) {
|
||||
const field = wrapForm.getFieldInstance(name);
|
||||
const fieldDom = getDOM(field);
|
||||
|
||||
if (field instanceof HTMLElement) {
|
||||
return field;
|
||||
}
|
||||
|
||||
if (field?.nativeElement instanceof HTMLElement) {
|
||||
return field.nativeElement;
|
||||
if (fieldDom) {
|
||||
return fieldDom;
|
||||
}
|
||||
|
||||
const fieldId = getFieldId(toArray(name), wrapForm.__INTERNAL__.name);
|
||||
|
@ -146,7 +146,7 @@
|
||||
"rc-tree": "~5.8.7",
|
||||
"rc-tree-select": "~5.21.0",
|
||||
"rc-upload": "~4.5.2",
|
||||
"rc-util": "^5.40.1",
|
||||
"rc-util": "^5.41.0",
|
||||
"scroll-into-view-if-needed": "^3.1.0",
|
||||
"throttle-debounce": "^5.0.0"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user