Skip to content

Commit 4779371

Browse files
authored
Merge branch 'react-component:master' into activeFilterOption
2 parents c023b4b + 7aa0c21 commit 4779371

File tree

10 files changed

+88
-166
lines changed

10 files changed

+88
-166
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rc-component/select",
3-
"version": "1.0.5",
3+
"version": "1.0.7",
44
"description": "React Select",
55
"engines": {
66
"node": ">=8.x"

src/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import SelectContext from './SelectContext';
4949
import type { SelectContextProps } from './SelectContext';
5050
import useCache from './hooks/useCache';
5151
import useFilterOptions from './hooks/useFilterOptions';
52-
import useId from './hooks/useId';
52+
import useId from '@rc-component/util/lib/hooks/useId';
5353
import useOptions from './hooks/useOptions';
5454
import useRefFunc from './hooks/useRefFunc';
5555
import type { FlattenOptionData } from './interface';

src/Selector/Input.tsx

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import * as React from 'react';
22
import classNames from 'classnames';
33
import { composeRef } from '@rc-component/util/lib/ref';
44
import { warning } from '@rc-component/util/lib/warning';
5+
import composeProps from '@rc-component/util/lib/composeProps';
56
import useBaseProps from '../hooks/useBaseProps';
7+
68
type InputRef = HTMLInputElement | HTMLTextAreaElement;
79

810
interface InputProps {
@@ -39,23 +41,13 @@ const Input: React.ForwardRefRenderFunction<InputRef, InputProps> = (props, ref)
3941
prefixCls,
4042
id,
4143
inputElement,
42-
disabled,
43-
tabIndex,
44-
autoFocus,
4544
autoComplete,
4645
editable,
4746
activeDescendantId,
4847
value,
49-
maxLength,
50-
onKeyDown,
51-
onMouseDown,
52-
onChange,
53-
onPaste,
54-
onCompositionStart,
55-
onCompositionEnd,
56-
onBlur,
5748
open,
5849
attrs,
50+
...restProps
5951
} = props;
6052

6153
const { classNames: contextClassNames, styles: contextStyles } = useBaseProps() || {};
@@ -64,35 +56,23 @@ const Input: React.ForwardRefRenderFunction<InputRef, InputProps> = (props, ref)
6456

6557
const { ref: originRef, props: originProps } = inputNode;
6658

67-
const {
68-
onKeyDown: onOriginKeyDown,
69-
onChange: onOriginChange,
70-
onMouseDown: onOriginMouseDown,
71-
onCompositionStart: onOriginCompositionStart,
72-
onCompositionEnd: onOriginCompositionEnd,
73-
onBlur: onOriginBlur,
74-
style,
75-
} = originProps;
76-
7759
warning(
7860
!('maxLength' in inputNode.props),
7961
`Passing 'maxLength' to input element directly may not work because input in BaseSelect is controlled.`,
8062
);
8163

8264
inputNode = React.cloneElement(inputNode, {
8365
type: 'search',
84-
...originProps,
66+
...composeProps(restProps, originProps, true),
67+
8568
// Override over origin props
8669
id,
8770
ref: composeRef(ref, originRef as any),
88-
disabled,
89-
tabIndex,
9071
autoComplete: autoComplete || 'off',
9172

92-
autoFocus,
9373
className: classNames(
9474
`${prefixCls}-selection-search-input`,
95-
inputNode?.props?.className,
75+
originProps.className,
9676
contextClassNames?.input,
9777
),
9878

@@ -105,48 +85,13 @@ const Input: React.ForwardRefRenderFunction<InputRef, InputProps> = (props, ref)
10585
'aria-activedescendant': open ? activeDescendantId : undefined,
10686
...attrs,
10787
value: editable ? value : '',
108-
maxLength,
10988
readOnly: !editable,
11089
unselectable: !editable ? 'on' : null,
11190

112-
style: { ...style, opacity: editable ? null : 0, ...contextStyles?.input },
113-
114-
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => {
115-
onKeyDown(event);
116-
if (onOriginKeyDown) {
117-
onOriginKeyDown(event);
118-
}
119-
},
120-
onMouseDown: (event: React.MouseEvent<HTMLElement>) => {
121-
onMouseDown(event);
122-
if (onOriginMouseDown) {
123-
onOriginMouseDown(event);
124-
}
125-
},
126-
onChange: (event: React.ChangeEvent<HTMLElement>) => {
127-
onChange(event);
128-
if (onOriginChange) {
129-
onOriginChange(event);
130-
}
131-
},
132-
onCompositionStart(event: React.CompositionEvent<HTMLElement>) {
133-
onCompositionStart(event);
134-
if (onOriginCompositionStart) {
135-
onOriginCompositionStart(event);
136-
}
137-
},
138-
onCompositionEnd(event: React.CompositionEvent<HTMLElement>) {
139-
onCompositionEnd(event);
140-
if (onOriginCompositionEnd) {
141-
onOriginCompositionEnd(event);
142-
}
143-
},
144-
onPaste,
145-
onBlur(event: React.FocusEvent<HTMLElement>) {
146-
onBlur(event);
147-
if (onOriginBlur) {
148-
onOriginBlur(event);
149-
}
91+
style: {
92+
...originProps.style,
93+
opacity: editable ? null : 0,
94+
...contextStyles?.input,
15095
},
15196
});
15297

src/hooks/useId.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/Select.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ describe('Select.Basic', () => {
924924
const onCompositionEnd = jest.fn();
925925
const textareaRef = jest.fn();
926926
const mouseDownPreventDefault = jest.fn();
927+
const onPaste = jest.fn();
927928
const { container } = render(
928929
<Select
929930
mode="combobox"
@@ -934,6 +935,7 @@ describe('Select.Basic', () => {
934935
onMouseDown={onMouseDown}
935936
onCompositionStart={onCompositionStart}
936937
onCompositionEnd={onCompositionEnd}
938+
onPaste={onPaste}
937939
ref={textareaRef}
938940
className="custom-input"
939941
/>
@@ -965,6 +967,13 @@ describe('Select.Basic', () => {
965967
expect(textareaRef).toHaveBeenCalled();
966968
expect(onCompositionStart).toHaveBeenCalled();
967969
expect(onCompositionEnd).toHaveBeenCalled();
970+
971+
fireEvent.paste(textareaEle, {
972+
target: { value: 'hi' },
973+
clipboardData: { getData: () => 'hi' },
974+
});
975+
expect(onPaste).toHaveBeenCalled();
976+
expect(textareaEle.value).toEqual('hi');
968977
});
969978

970979
it('not override customize props', () => {

tests/__snapshots__/Combobox.test.tsx.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ exports[`Select.Combobox renders controlled correctly 1`] = `
1515
>
1616
<input
1717
aria-autocomplete="list"
18-
aria-controls="rc_select_TEST_OR_SSR_list"
18+
aria-controls="test-id_list"
1919
aria-expanded="false"
2020
aria-haspopup="listbox"
21-
aria-owns="rc_select_TEST_OR_SSR_list"
21+
aria-owns="test-id_list"
2222
autocomplete="off"
2323
class="rc-select-selection-search-input"
24-
id="rc_select_TEST_OR_SSR"
24+
id="test-id"
2525
role="combobox"
2626
type="search"
2727
value=""
@@ -52,13 +52,13 @@ exports[`Select.Combobox renders correctly 1`] = `
5252
>
5353
<input
5454
aria-autocomplete="list"
55-
aria-controls="rc_select_TEST_OR_SSR_list"
55+
aria-controls="test-id_list"
5656
aria-expanded="false"
5757
aria-haspopup="listbox"
58-
aria-owns="rc_select_TEST_OR_SSR_list"
58+
aria-owns="test-id_list"
5959
autocomplete="off"
6060
class="rc-select-selection-search-input"
61-
id="rc_select_TEST_OR_SSR"
61+
id="test-id"
6262
role="combobox"
6363
type="search"
6464
value=""

tests/__snapshots__/Multiple.test.tsx.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ exports[`Select.Multiple max tag render not display maxTagPlaceholder if maxTagC
2323
>
2424
<input
2525
aria-autocomplete="list"
26-
aria-controls="rc_select_TEST_OR_SSR_list"
26+
aria-controls="test-id_list"
2727
aria-expanded="false"
2828
aria-haspopup="listbox"
29-
aria-owns="rc_select_TEST_OR_SSR_list"
29+
aria-owns="test-id_list"
3030
autocomplete="off"
3131
class="rc-select-selection-search-input"
32-
id="rc_select_TEST_OR_SSR"
32+
id="test-id"
3333
readonly=""
3434
role="combobox"
3535
style="opacity: 0;"
@@ -147,13 +147,13 @@ exports[`Select.Multiple max tag render truncates tags by maxTagCount and show m
147147
>
148148
<input
149149
aria-autocomplete="list"
150-
aria-controls="rc_select_TEST_OR_SSR_list"
150+
aria-controls="test-id_list"
151151
aria-expanded="false"
152152
aria-haspopup="listbox"
153-
aria-owns="rc_select_TEST_OR_SSR_list"
153+
aria-owns="test-id_list"
154154
autocomplete="off"
155155
class="rc-select-selection-search-input"
156-
id="rc_select_TEST_OR_SSR"
156+
id="test-id"
157157
readonly=""
158158
role="combobox"
159159
style="opacity: 0;"
@@ -269,13 +269,13 @@ exports[`Select.Multiple max tag render truncates tags by maxTagCount and show m
269269
>
270270
<input
271271
aria-autocomplete="list"
272-
aria-controls="rc_select_TEST_OR_SSR_list"
272+
aria-controls="test-id_list"
273273
aria-expanded="false"
274274
aria-haspopup="listbox"
275-
aria-owns="rc_select_TEST_OR_SSR_list"
275+
aria-owns="test-id_list"
276276
autocomplete="off"
277277
class="rc-select-selection-search-input"
278-
id="rc_select_TEST_OR_SSR"
278+
id="test-id"
279279
readonly=""
280280
role="combobox"
281281
style="opacity: 0;"
@@ -374,13 +374,13 @@ exports[`Select.Multiple max tag render truncates values by maxTagTextLength 1`]
374374
>
375375
<input
376376
aria-autocomplete="list"
377-
aria-controls="rc_select_TEST_OR_SSR_list"
377+
aria-controls="test-id_list"
378378
aria-expanded="false"
379379
aria-haspopup="listbox"
380-
aria-owns="rc_select_TEST_OR_SSR_list"
380+
aria-owns="test-id_list"
381381
autocomplete="off"
382382
class="rc-select-selection-search-input"
383-
id="rc_select_TEST_OR_SSR"
383+
id="test-id"
384384
readonly=""
385385
role="combobox"
386386
style="opacity: 0;"

0 commit comments

Comments
 (0)