react-select icon indicating copy to clipboard operation
react-select copied to clipboard

max-length support for searchable field

Open saurabhnemade opened this issue 6 years ago • 3 comments

is there any way to pass max-length to searchable input field?

By wrapping components.Input in components prop adds max-length but somehow it requires two tabs to get out after selection to move to next element.

More importantly type of components.Input props (InputProps) does not include HTMLInputProps, so a lot of arguments need to be passed like:

const Input = useCallback((props: InputProps) =>

    <components.Input {...props} {...extendedInputProps } aria-label={`label for ${ariaLabel || 'Select Dropdown'}`}/>
  , []);

If we don' pass them like above, we get error as property does not exists on Input component.

saurabhnemade avatar Feb 04 '20 09:02 saurabhnemade

I don't get why https://github.com/JedWatson/react-select/issues/1280 was close, can we please don't close this one ? I'm happy to submit a PR if you need help.

ruben0626 avatar Feb 04 '20 20:02 ruben0626

Hi @ruben0626, the author themselves closed the issue shortly after creating it, and has not since replied. We'll take a look at this issue in more detail when we can.

bladey avatar Jun 19 '20 02:06 bladey

Greetings @ruben0626

A working solution to this is can be done by writing a custom Input component and leveraging the selectProps passed to it. All props passed to the Input are applied directly to the input element as attributes/props so this would be one approach.

const Input = props => {
  const { maxLength } = props.selectProps;
  return <components.Input {{...props }} maxLength={maxLength} />
}

const MySelect = props => <Select components={{Input}} maxLength={props.maxLength} ... />

This approach should work with any other props that you want to apply to the input as well (ie: required, readOnly, etc...)

If there are any other questions, please feel free to reply and we can reopen this.

ebonow avatar Dec 03 '20 02:12 ebonow