question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:21
  • Comments:8

github_iconTop GitHub Comments

10reactions
Rall3ncommented, Jan 10, 2019

@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

8reactions
tutokcommented, Feb 24, 2017

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} />
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the alternative of [clearable] in ng-select - Stack Overflow
if 'clearable' property is set to false, and clearOnBackspace is set to true, user can remove single item using backspace button. · use...
Read more >
Delete & Backspace keys are not working in Excel (Desktop
Backspace clears the content of the active cell i.e., it only can clear the first cell where we start selecting. In other Office...
Read more >
API - React Select
Clear all values when the user presses escape AND the menu is closed. boolean ... The cache will remain until cacheOptions changes value....
Read more >
Backspace clears the ComboBox SelectedItem - Telerik
Backspace clears the ComboBox SelectedItem ... I have set the IsEditable property to False, so the user can only select values from the...
Read more >
QLineEdit Class | Qt Widgets 6.4.1
Text can be selected with setSelection() or selectAll(), ... This property holds whether the line edit displays a clear button when it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found