Skip to content

Commit e97c5ab

Browse files
authored
fix: expose maxLength (#771)
* fix: expose maxLength and raise customInputElement maxLength priotiry * test: add test * test: update test * chore: code clean * test: fix warning * chore: add warning * chore: remove useless test * chore: code clean
1 parent 446dd09 commit e97c5ab

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/BaseSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ export interface BaseSelectPrivateProps {
108108
) => void;
109109
/** Trigger when search text match the `tokenSeparators`. Will provide split content */
110110
onSearchSplit?: (words: string[]) => void;
111-
maxLength?: number;
112111

113112
// >>> Dropdown
114113
OptionList: React.ForwardRefExoticComponent<
@@ -126,6 +125,7 @@ export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttri
126125
showSearch?: boolean;
127126
tagRender?: (props: CustomTagProps) => React.ReactElement;
128127
direction?: 'ltr' | 'rtl';
128+
maxLength?: number;
129129

130130
// MISC
131131
tabIndex?: number;

src/Selector/Input.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import classNames from 'classnames';
33
import { composeRef } from 'rc-util/lib/ref';
4+
import { warning } from 'rc-util/lib/warning';
45

56
type InputRef = HTMLInputElement | HTMLTextAreaElement;
67

@@ -69,6 +70,11 @@ const Input: React.RefForwardingComponent<InputRef, InputProps> = (
6970
style,
7071
} = originProps;
7172

73+
warning(
74+
!('maxLength' in inputNode.props),
75+
`Passing 'maxLength' to input element directly may not work because input in BaseSelect is controlled.`,
76+
);
77+
7278
inputNode = React.cloneElement(inputNode, {
7379
type: 'search',
7480
...originProps,

src/Selector/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface SelectorProps {
6161
searchValue: string;
6262
activeValue: string;
6363
inputElement: JSX.Element;
64+
maxLength?: number;
6465

6566
autoFocus?: boolean;
6667
activeDescendantId?: string;

tests/Combobox.test.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ describe('Select.Combobox', () => {
152152

153153
public render() {
154154
const options = this.state.data.map((item) => (
155-
<Option value={item.key}>{item.label}</Option>
155+
<Option key={item.key} value={item.key}>
156+
{item.label}
157+
</Option>
156158
));
157159
return (
158160
<Select
@@ -199,7 +201,9 @@ describe('Select.Combobox', () => {
199201

200202
public render() {
201203
const options = this.state.data.map((item) => (
202-
<Option value={item.key}>{item.label}</Option>
204+
<Option key={item.key} value={item.key}>
205+
{item.label}
206+
</Option>
203207
));
204208
return (
205209
<Select
@@ -361,7 +365,9 @@ describe('Select.Combobox', () => {
361365
return (
362366
<Select mode="combobox" onChange={this.updateOptions}>
363367
{this.state.options.map((opt) => (
364-
<Option value={opt}>{opt}</Option>
368+
<Option key={opt} value={opt}>
369+
{opt}
370+
</Option>
365371
))}
366372
</Select>
367373
);

0 commit comments

Comments
 (0)