Skip to content

Commit 918a34e

Browse files
committed
fix: getInputElement className missing
ant-design/ant-design#29679
1 parent d83bd8a commit 918a34e

File tree

3 files changed

+37
-59
lines changed

3 files changed

+37
-59
lines changed

examples/suggest.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,39 @@ import '../assets/index.less';
55

66
import { fetch } from './common/tbFetchSuggest';
77

8-
const Input = React.forwardRef<HTMLInputElement>((props, ref) => <input ref={ref} {...props} />);
8+
const Input = React.forwardRef<HTMLInputElement, any>((props, ref) => (
9+
<input ref={ref} {...props} />
10+
));
911

1012
class Test extends React.Component {
1113
state = {
1214
data: [],
1315
value: '',
1416
};
1517

16-
onKeyDown = e => {
18+
onKeyDown = (e) => {
1719
if (e.keyCode === 13) {
1820
const { value } = this.state;
1921
console.log('onEnter', value);
2022
this.jump(value);
2123
}
2224
};
2325

24-
onSelect = value => {
26+
onSelect = (value) => {
2527
console.log('select ', value);
2628
this.jump(value);
2729
};
2830

29-
jump = v => {
31+
jump = (v) => {
3032
console.log('jump ', v);
3133
// location.href = 'https://s.taobao.com/search?q=' + encodeURIComponent(v);
3234
};
3335

34-
fetchData = value => {
36+
fetchData = (value) => {
3537
this.setState({
3638
value,
3739
});
38-
fetch(value, data => {
40+
fetch(value, (data) => {
3941
this.setState({
4042
data,
4143
});
@@ -44,7 +46,7 @@ class Test extends React.Component {
4446

4547
render() {
4648
const { data, value } = this.state;
47-
const options = data.map(d => <Option key={d.value}>{d.text}</Option>);
49+
const options = data.map((d) => <Option key={d.value}>{d.text}</Option>);
4850
return (
4951
<div>
5052
<h2>suggest</h2>
@@ -56,7 +58,7 @@ class Test extends React.Component {
5658
value={value}
5759
placeholder="placeholder"
5860
defaultActiveFirstOption={false}
59-
getInputElement={() => <Input />}
61+
getInputElement={() => <Input className="custom-input" />}
6062
showArrow={false}
6163
notFoundContent=""
6264
onChange={this.fetchData}

src/Selector/Input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import classNames from 'classnames';
23
import { composeRef } from 'rc-util/lib/ref';
34

45
type InputRef = HTMLInputElement | HTMLTextAreaElement;
@@ -77,7 +78,7 @@ const Input: React.RefForwardingComponent<InputRef, InputProps> = (
7778
autoComplete: autoComplete || 'off',
7879
type: 'search',
7980
autoFocus,
80-
className: `${prefixCls}-selection-search-input`,
81+
className: classNames(`${prefixCls}-selection-search-input`, inputNode?.props?.className),
8182
style: { ...style, opacity: editable ? null : 0 },
8283
role: 'combobox',
8384
'aria-expanded': open,

tests/Select.test.tsx

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import React from 'react';
44
import { act } from 'react-dom/test-utils';
55
import { resetWarned } from 'rc-util/lib/warning';
66
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
7-
import Select, { OptGroup, Option, SelectProps } from '../src';
7+
import type { SelectProps } from '../src';
8+
import Select, { OptGroup, Option } from '../src';
89
import focusTest from './shared/focusTest';
910
import blurTest from './shared/blurTest';
1011
import keyDownTest from './shared/keyDownTest';
@@ -148,18 +149,12 @@ describe('Select.Basic', () => {
148149
</Select>,
149150
);
150151
expect(
151-
wrapper1
152-
.find('.rc-select-dropdown')
153-
.first()
154-
.hasClass('rc-select-dropdown-empty'),
152+
wrapper1.find('.rc-select-dropdown').first().hasClass('rc-select-dropdown-empty'),
155153
).toBeFalsy();
156154

157155
const wrapper2 = mount(<Select open />);
158156
expect(
159-
wrapper2
160-
.find('.rc-select-dropdown')
161-
.first()
162-
.hasClass('rc-select-dropdown-empty'),
157+
wrapper2.find('.rc-select-dropdown').first().hasClass('rc-select-dropdown-empty'),
163158
).toBeTruthy();
164159
});
165160

@@ -189,7 +184,7 @@ describe('Select.Basic', () => {
189184
expect(
190185
wrapper
191186
.find('.rc-select-item-option-selected div.rc-select-item-option-content')
192-
.map(node => node.text()),
187+
.map((node) => node.text()),
193188
).toEqual(['1', '2']);
194189
});
195190

@@ -250,12 +245,7 @@ describe('Select.Basic', () => {
250245
<Option value="2">Two</Option>
251246
</Select>,
252247
);
253-
expect(
254-
wrapper
255-
.find('input')
256-
.getDOMNode()
257-
.getAttribute('readonly'),
258-
).toBeFalsy();
248+
expect(wrapper.find('input').getDOMNode().getAttribute('readonly')).toBeFalsy();
259249
});
260250

261251
it('filter options by "value" prop by default', () => {
@@ -657,7 +647,7 @@ describe('Select.Basic', () => {
657647
});
658648
});
659649

660-
[KeyCode.ENTER, KeyCode.DOWN].forEach(keyCode => {
650+
[KeyCode.ENTER, KeyCode.DOWN].forEach((keyCode) => {
661651
it('open on key press', () => {
662652
const wrapper = mount(<Select />);
663653
wrapper.find('input').simulate('keyDown', { keyCode });
@@ -726,7 +716,7 @@ describe('Select.Basic', () => {
726716
open: true,
727717
};
728718

729-
public onDropdownVisibleChange = open => {
719+
public onDropdownVisibleChange = (open) => {
730720
this.setState({ open });
731721
};
732722

@@ -779,6 +769,7 @@ describe('Select.Basic', () => {
779769
onCompositionStart={onCompositionStart}
780770
onCompositionEnd={onCompositionEnd}
781771
ref={textareaRef}
772+
className="custom-input"
782773
/>
783774
)}
784775
>
@@ -800,6 +791,7 @@ describe('Select.Basic', () => {
800791

801792
selectItem(wrapper);
802793
expect(wrapper.find('textarea').props().value).toEqual('1');
794+
expect(wrapper.find('textarea').hasClass('custom-input')).toBe(true);
803795
expect(mouseDownPreventDefault).not.toHaveBeenCalled();
804796
expect(onKeyDown).toHaveBeenCalled();
805797
expect(onChange).toHaveBeenCalled();
@@ -907,7 +899,7 @@ describe('Select.Basic', () => {
907899
});
908900

909901
it('warns on invalid children', () => {
910-
const Foo = value => <div>foo{value}</div>;
902+
const Foo = (value) => <div>foo{value}</div>;
911903
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => null);
912904
mount(
913905
<Select open>
@@ -1031,7 +1023,7 @@ describe('Select.Basic', () => {
10311023
const wrapper = mount(
10321024
<Select
10331025
open
1034-
dropdownRender={menu => (
1026+
dropdownRender={(menu) => (
10351027
<div>
10361028
<div className="dropdown-custom-node">CUSTOM NODE</div>
10371029
{menu}
@@ -1053,7 +1045,7 @@ describe('Select.Basic', () => {
10531045
const wrapper = mount(
10541046
<Select
10551047
onMouseDown={onMouseDown}
1056-
dropdownRender={menu => (
1048+
dropdownRender={(menu) => (
10571049
<div>
10581050
<div id="dropdown-custom-node" onClick={onChildClick}>
10591051
CUSTOM NODE
@@ -1202,12 +1194,7 @@ describe('Select.Basic', () => {
12021194
/>,
12031195
);
12041196
toggleOpen(wrapper);
1205-
expect(
1206-
wrapper
1207-
.find('.rc-select-dropdown')
1208-
.last()
1209-
.props().style.minWidth,
1210-
).toBe(1000);
1197+
expect(wrapper.find('.rc-select-dropdown').last().props().style.minWidth).toBe(1000);
12111198

12121199
// dropdownMatchSelectWidth is false means close virtual scroll
12131200
expect(wrapper.find('.rc-select-item')).toHaveLength(options.length);
@@ -1504,7 +1491,7 @@ describe('Select.Basic', () => {
15041491
});
15051492

15061493
describe('reset value to undefined should reset display value', () => {
1507-
[undefined].forEach(value => {
1494+
[undefined].forEach((value) => {
15081495
it(`to ${value}`, () => {
15091496
const wrapper = mount(<Select value="light" />);
15101497
expect(wrapper.find('.rc-select-selection-item').text()).toEqual('light');
@@ -1588,7 +1575,12 @@ describe('Select.Basic', () => {
15881575
</Select>,
15891576
);
15901577

1591-
[[1, '1'], [null, 'No'], [0, '0'], ['', 'Empty']].forEach(([value, showValue], index) => {
1578+
[
1579+
[1, '1'],
1580+
[null, 'No'],
1581+
[0, '0'],
1582+
['', 'Empty'],
1583+
].forEach(([value, showValue], index) => {
15921584
toggleOpen(wrapper);
15931585
selectItem(wrapper, index);
15941586
expect(onChange).toHaveBeenCalledWith(value, expect.anything());
@@ -1632,11 +1624,7 @@ describe('Select.Basic', () => {
16321624
// This can not test function called with jest spy, coverage only
16331625
it('mouse enter to refresh', () => {
16341626
const wrapper = mount(<Select options={[{ value: 903, label: 'Bamboo' }]} open />);
1635-
wrapper
1636-
.find('List')
1637-
.find('div')
1638-
.first()
1639-
.simulate('mouseenter');
1627+
wrapper.find('List').find('div').first().simulate('mouseenter');
16401628
});
16411629

16421630
it('filterSort should work', () => {
@@ -1657,28 +1645,15 @@ describe('Select.Basic', () => {
16571645
);
16581646

16591647
wrapper.find('input').simulate('change', { target: { value: 'i' } });
1660-
expect(
1661-
wrapper
1662-
.find('.rc-select-item-option-content')
1663-
.first()
1664-
.text(),
1665-
).toBe('Communicated');
1648+
expect(wrapper.find('.rc-select-item-option-content').first().text()).toBe('Communicated');
16661649
});
16671650

16681651
it('correctly handles the `tabIndex` prop', () => {
16691652
const wrapper = mount(<Select tabIndex={0} />);
1670-
expect(
1671-
wrapper
1672-
.find('.rc-select')
1673-
.getDOMNode()
1674-
.getAttribute('tabindex'),
1675-
).toBeNull();
1653+
expect(wrapper.find('.rc-select').getDOMNode().getAttribute('tabindex')).toBeNull();
16761654

16771655
expect(
1678-
wrapper
1679-
.find('input.rc-select-selection-search-input')
1680-
.getDOMNode()
1681-
.getAttribute('tabindex'),
1656+
wrapper.find('input.rc-select-selection-search-input').getDOMNode().getAttribute('tabindex'),
16821657
).toBe('0');
16831658
});
16841659
});

0 commit comments

Comments
 (0)