Skip to content

Commit c79f5e5

Browse files
authored
Merge branch 'master' into fix/tabindex-prop
2 parents 8895015 + 7781194 commit c79f5e5

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

examples/combobox.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ class Combobox extends React.Component {
8989
onInputKeyDown={this.onKeyDown}
9090
notFoundContent=""
9191
allowClear
92-
placeholder="please select"
92+
placeholder="please input, max len: 10"
9393
value={value}
94+
maxLength={10}
9495
mode="combobox"
9596
backfill
9697
onFocus={() => console.log('focus')}
@@ -112,11 +113,7 @@ class Combobox extends React.Component {
112113
mode="combobox"
113114
style={{ width: 200 }}
114115
getInputElement={() => (
115-
<textarea
116-
style={{ background: 'red' }}
117-
rows={3}
118-
ref={this.textareaRef}
119-
/>
116+
<textarea style={{ background: 'red' }} rows={3} ref={this.textareaRef} />
120117
)}
121118
options={[{ value: 'light' }, { value: 'bamboo' }]}
122119
allowClear

package.json

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

src/Selector/Input.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface InputProps {
1313
editable: boolean;
1414
accessibilityIndex: number;
1515
value: string;
16+
maxLength?: number;
1617
open: boolean;
1718
tabIndex: number;
1819
/** Pass accessibility props to input */
@@ -42,6 +43,7 @@ const Input: React.RefForwardingComponent<InputRef, InputProps> = (
4243
editable,
4344
accessibilityIndex,
4445
value,
46+
maxLength,
4547
onKeyDown,
4648
onMouseDown,
4749
onChange,
@@ -86,6 +88,7 @@ const Input: React.RefForwardingComponent<InputRef, InputProps> = (
8688
'aria-activedescendant': `${id}_list_${accessibilityIndex}`,
8789
...attrs,
8890
value: editable ? value : '',
91+
maxLength,
8992
readOnly: !editable,
9093
unselectable: !editable ? 'on' : null,
9194
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => {

src/Selector/SingleSelector.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const SingleSelector: React.FC<SelectorProps> = props => {
2828
showSearch,
2929
searchValue,
3030
activeValue,
31+
maxLength,
3132

3233
onInputKeyDown,
3334
onInputMouseDown,
@@ -88,6 +89,7 @@ const SingleSelector: React.FC<SelectorProps> = props => {
8889
onCompositionEnd={onInputCompositionEnd}
8990
tabIndex={tabIndex}
9091
attrs={pickAttrs(props, true)}
92+
maxLength={combobox && maxLength}
9193
/>
9294
</span>
9395

src/Selector/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface InnerSelectorProps {
3333
accessibilityIndex: number;
3434
open: boolean;
3535
tabIndex?: number;
36+
maxLength?: number;
3637

3738
onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
3839
onInputMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;

src/generate.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export interface SelectProps<OptionsType extends object[], ValueType> extends Re
7474
value?: ValueType;
7575
defaultValue?: ValueType;
7676
labelInValue?: boolean;
77+
/** Config max length of input. This is only work when `mode` is `combobox` */
78+
maxLength?: number;
7779

7880
// Search
7981
inputValue?: string;
@@ -188,7 +190,7 @@ export interface GenerateConfig<OptionsType extends object[]> {
188190
/** Convert single raw value into { label, value } format. Will be called by each value */
189191
getLabeledValue: GetLabeledValue<FlattenOptionsType<OptionsType>>;
190192
filterOptions: FilterOptions<OptionsType>;
191-
findValueOption: // Need still support legacy ts api
193+
findValueOption: // Need still support legacy ts api
192194
| ((values: RawValueType[], options: FlattenOptionsType<OptionsType>) => OptionsType)
193195
// New API add prevValueOptions support
194196
| ((

tests/Combobox.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,16 @@ describe('Select.Combobox', () => {
447447

448448
expect(wrapper.find('input').props().value).toBe('');
449449
});
450+
451+
describe('maxLength', () => {
452+
it('should support', () => {
453+
const wrapper = mount(<Select maxLength={6} />);
454+
expect(wrapper.find('input').props().maxLength).toBeFalsy();
455+
});
456+
457+
it('normal should not support', () => {
458+
const wrapper = mount(<Select mode="combobox" maxLength={6} />);
459+
expect(wrapper.find('input').props().maxLength).toBe(6);
460+
});
461+
});
450462
});

0 commit comments

Comments
 (0)