Skip to content

Commit c84b507

Browse files
authored
fix: React 18.3 warning (#1046)
1 parent ebc3f68 commit c84b507

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/BaseSelect/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,12 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
764764
builtinPlacements={builtinPlacements}
765765
getPopupContainer={getPopupContainer}
766766
empty={emptyOptions}
767-
getTriggerDOMNode={() => selectorDomRef.current}
767+
getTriggerDOMNode={(node) =>
768+
// TODO: This is workaround and should be removed in `rc-select`
769+
// And use new standard `nativeElement` for ref.
770+
// But we should update `rc-resize-observer` first.
771+
selectorDomRef.current || node
772+
}
768773
onPopupVisibleChange={onTriggerVisibleChange}
769774
onPopupMouseEnter={onPopupMouseEnter}
770775
>

src/SelectTrigger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export interface SelectTriggerProps {
7373
dropdownAlign: AlignType;
7474
empty: boolean;
7575

76-
getTriggerDOMNode: () => HTMLElement;
76+
getTriggerDOMNode: (node: HTMLElement) => HTMLElement;
7777
onPopupVisibleChange?: (visible: boolean) => void;
7878

7979
onPopupMouseEnter: () => void;

tests/React.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from 'react';
2+
import Select from '../src';
3+
import { injectRunAllTimers } from './utils/common';
4+
import { render } from '@testing-library/react';
5+
6+
describe('React', () => {
7+
injectRunAllTimers(jest);
8+
9+
beforeEach(() => {
10+
jest.useFakeTimers();
11+
});
12+
13+
afterEach(() => {
14+
jest.useRealTimers();
15+
});
16+
17+
it('not warning findDOMNode', () => {
18+
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
19+
20+
render(<Select open getRawInputElement={() => <a />} />);
21+
22+
expect(errSpy).not.toHaveBeenCalled();
23+
errSpy.mockRestore();
24+
});
25+
});

0 commit comments

Comments
 (0)