Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions examples/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ class Combobox extends React.Component {
onInputKeyDown={this.onKeyDown}
notFoundContent=""
allowClear
placeholder="please select"
placeholder="please input, max len: 10"
value={value}
maxLength={10}
mode="combobox"
backfill
onFocus={() => console.log('focus')}
Expand All @@ -112,11 +113,7 @@ class Combobox extends React.Component {
mode="combobox"
style={{ width: 200 }}
getInputElement={() => (
<textarea
style={{ background: 'red' }}
rows={3}
ref={this.textareaRef}
/>
<textarea style={{ background: 'red' }} rows={3} ref={this.textareaRef} />
)}
options={[{ value: 'light' }, { value: 'bamboo' }]}
allowClear
Expand Down
3 changes: 3 additions & 0 deletions src/Selector/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface InputProps {
editable: boolean;
accessibilityIndex: number;
value: string;
maxLength?: number;
open: boolean;
tabIndex: number;
/** Pass accessibility props to input */
Expand Down Expand Up @@ -42,6 +43,7 @@ const Input: React.RefForwardingComponent<InputRef, InputProps> = (
editable,
accessibilityIndex,
value,
maxLength,
onKeyDown,
onMouseDown,
onChange,
Expand Down Expand Up @@ -86,6 +88,7 @@ const Input: React.RefForwardingComponent<InputRef, InputProps> = (
'aria-activedescendant': `${id}_list_${accessibilityIndex}`,
...attrs,
value: editable ? value : '',
maxLength,
readOnly: !editable,
unselectable: !editable ? 'on' : null,
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => {
Expand Down
2 changes: 2 additions & 0 deletions src/Selector/SingleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const SingleSelector: React.FC<SelectorProps> = props => {
showSearch,
searchValue,
activeValue,
maxLength,

onInputKeyDown,
onInputMouseDown,
Expand Down Expand Up @@ -88,6 +89,7 @@ const SingleSelector: React.FC<SelectorProps> = props => {
onCompositionEnd={onInputCompositionEnd}
tabIndex={tabIndex}
attrs={pickAttrs(props, true)}
maxLength={combobox && maxLength}
/>
</span>

Expand Down
1 change: 1 addition & 0 deletions src/Selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface InnerSelectorProps {
accessibilityIndex: number;
open: boolean;
tabIndex?: number;
maxLength?: number;

onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
onInputMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
Expand Down
4 changes: 3 additions & 1 deletion src/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export interface SelectProps<OptionsType extends object[], ValueType> extends Re
value?: ValueType;
defaultValue?: ValueType;
labelInValue?: boolean;
/** Config max length of input. This is only work when `mode` is `combobox` */
maxLength?: number;

// Search
inputValue?: string;
Expand Down Expand Up @@ -188,7 +190,7 @@ export interface GenerateConfig<OptionsType extends object[]> {
/** Convert single raw value into { label, value } format. Will be called by each value */
getLabeledValue: GetLabeledValue<FlattenOptionsType<OptionsType>>;
filterOptions: FilterOptions<OptionsType>;
findValueOption:// Need still support legacy ts api
findValueOption: // Need still support legacy ts api
| ((values: RawValueType[], options: FlattenOptionsType<OptionsType>) => OptionsType)
// New API add prevValueOptions support
| ((
Expand Down
12 changes: 12 additions & 0 deletions tests/Combobox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,16 @@ describe('Select.Combobox', () => {

expect(wrapper.find('input').props().value).toBe('');
});

describe('maxLength', () => {
it('should support', () => {
const wrapper = mount(<Select maxLength={6} />);
expect(wrapper.find('input').props().maxLength).toBeFalsy();
});

it('normal should not support', () => {
const wrapper = mount(<Select mode="combobox" maxLength={6} />);
expect(wrapper.find('input').props().maxLength).toBe(6);
});
});
});