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

Select with `clearable={false}` can still be cleared with backspace

Open dallonf opened this issue 9 years ago • 9 comments

Here's a Plunker: https://plnkr.co/edit/ZaFyPW0zGqcf2oWeVnaL?p=preview

Note that although it has clearable={false}, you can still clear the value by focusing the field and pressing Backspace. To disable this behavior, you have to also explicitly set deleteRemoves={false}.

This is surprising to me; I would expect that clearable={false} would mean that you can never get a null (or empty array, to be more precise) value from the field.

Maybe deleteRemoves should default to the value of clearable? Or require both deleteRemoves and clearable to be true for the backspace behavior?

dallonf avatar Feb 16 '17 15:02 dallonf

Actually I have opposite problem, I specified backspaceRemoves={true} deleteRemoves={true} and I can not remove selected value until I start typing.

return (
    <Select.AsyncCreatable name={input.name} placeholder={placeholder} 
    backspaceRemoves={true} deleteRemoves={true} searchable={true} 
    arrowRenderer={arrowRenderer} searchPromptText={t('lookupTypeToSearch')} 
    promptTextCreator={x => t('lookupCreate', { replace: { item: x } })} value={input.value} 
    valueKey={props.valueKey} labelKey={props.labelKey} loadOptions={onLoadOptionsHandler}
    onChange={onChangeHandler} />
);

marcinvalas avatar Feb 24 '17 15:02 marcinvalas

@dallonf I have the same issue at the version 1.0.0-rc.4

genomanetwork avatar May 23 '17 22:05 genomanetwork

Hi @dallonf to me clearable refers to the x icon. However I could see the confusion for users that may think that means also the delete key. Since we want this to be configurable, I don't think setting a default based on another prop is ideal. Maybe just document this behavior more thoroughly?

@tutok this sounds like a separate issue. Do you mind opening an issue with a reproducible case?

agirton avatar May 24 '17 04:05 agirton

I feel like this is inconsistent at the moment, as escapeRemoves does depend on clearable being true, whereas backspaceRemoves and deleteRemoves do not.

jackwilsdon avatar Nov 13 '17 10:11 jackwilsdon

Any update here? I was very surprised to find out that when I set clearable to false, my select is in fact, still clearable. (RE @agirton's comment: if that's really what clearable is supposed to mean, then we should call it something like showClearIcon.)

Would you be open to a PR that sets backspaceRemoves to false and deleteRemoves to false if they are not already specified and clearable is set to false?

jfly avatar May 23 '18 22:05 jfly

I would suggest to have a property showClearIcon so that we are able to decide which the way of clearing is more appropriate in actual usage context, either by Backspace, Delete or mouse click icon. With current latest code, we cannot hide clear icon and allow only backspace/delete to clear.

pohsoon avatar Jan 10 '19 09:01 pohsoon

@pohsoon Yes you can. react-select v2 gives you the ability to redefine the internal components with its components prop. Components that can be redefined also include the ClearIndicator. You just have to set the ClearIndicator in components prop to null, and the indicator will not render, but the clearing functionality will still be present.

<Select
    { ... }
    components={{
        ClearIndicator: null
    }}
 />

CodeSandbox

Rall3n avatar Jan 10 '19 09:01 Rall3n

@Rall3n Good to know that. Thank you!

pohsoon avatar Jan 10 '19 15:01 pohsoon

For anyone wondering, now there is a new option backspaceRemovesValue which can optionally determine whether backspace can clear values or not

shivamjjha avatar Mar 13 '23 06:03 shivamjjha