Skip to content

Commit e4e1544

Browse files
authored
feat: support nativeElement (#1047)
1 parent ddc151f commit e4e1544

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/BaseSelect/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface BaseSelectRef {
7575
focus: (options?: FocusOptions) => void;
7676
blur: () => void;
7777
scrollTo: ScrollTo;
78+
nativeElement: HTMLElement;
7879
}
7980

8081
export interface BaseSelectPrivateProps {
@@ -329,6 +330,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
329330
focus: selectorRef.current?.focus,
330331
blur: selectorRef.current?.blur,
331332
scrollTo: (arg) => listRef.current?.scrollTo(arg),
333+
nativeElement: containerRef.current || selectorDomRef.current,
332334
}));
333335

334336
// ========================== Search Value ==========================

tests/React.test.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import Select from '../src';
2+
import Select, { type BaseSelectRef } from '../src';
33
import { injectRunAllTimers } from './utils/common';
44
import { render } from '@testing-library/react';
55

@@ -22,4 +22,22 @@ describe('React', () => {
2222
expect(errSpy).not.toHaveBeenCalled();
2323
errSpy.mockRestore();
2424
});
25+
26+
describe('nativeElement', () => {
27+
it('work', () => {
28+
const selectRef = React.createRef<BaseSelectRef>();
29+
const { container } = render(<Select ref={selectRef} />);
30+
31+
expect(selectRef.current?.nativeElement).toBe(container.querySelector('.rc-select'));
32+
});
33+
34+
it('getRawInputElement', () => {
35+
const selectRef = React.createRef<BaseSelectRef>();
36+
const { container } = render(
37+
<Select ref={selectRef} getRawInputElement={() => <a className="bamboo" />} />,
38+
);
39+
40+
expect(selectRef.current?.nativeElement).toBe(container.querySelector('a.bamboo'));
41+
});
42+
});
2543
});

0 commit comments

Comments
 (0)