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

Feature request: ability to switch off editable mode.

Open gsanta opened this issue 8 years ago • 11 comments

In our project we use dropdowns in varous places, and I would like to use exclusively react-selectize everywhere. But in some places we don't need the search ability of react-selectize.

It would be nice if we could switch it off and have it work like a simple dropdown.

(In the api there is an 'editable' option, but I couldn't really figure out what that means)

gsanta avatar Apr 15 '16 16:04 gsanta

react-selectize is a controlled component, so if you need to block the search capability all you need to do is set the search prop to an empty string:

<SimpleSelect
    search = ""
/>

furqanZafar avatar Apr 16 '16 15:04 furqanZafar

You are right that search='' does not allow to type into the component. But the cursor is still blinking there and the input can be removed with backspace.

What I really meant is the functionality similar to a regular dropdown, where you can only select from the dropdown list, with no cursor and no backspace functionality. (Because I guess if you don't want the user to be able to search the blinking cursor is a little misleading)

gsanta avatar Apr 16 '16 16:04 gsanta

I was using previously react-select, and for example there is a 'searchable' property, that does exactly what I'm talking about.

(that's an other story why I abandoned react-select in general I like react-selectize way better)

gsanta avatar Apr 16 '16 16:04 gsanta

yes this mode is not supported at the moment via a prop, but as a workaround you can hide the blinking cursor using css something like display: none for the resizable-input css-class

furqanZafar avatar Apr 16 '16 16:04 furqanZafar

Yes I tried it, but unfortunately, it ruins the cursor navigation (you can not navigate through the dropdown list with the cursor, and even if you hit enter or click with the mouse outside of the dropdown the dropdown list won't close). I think it must depends on some input event (blur maybe), and setting it to display: none, the event wont fire anymore.

I also tried to set the opacity to zero, it worked for chrome and firefox, but not for IE (the same navigation problem).

So I haven't been able to find a general css solution for this problem.

gsanta avatar Apr 16 '16 16:04 gsanta

I'm also interested in this feature. I'm trying to get away from react-select because it does not support the dropdown direction like this component does, but then this one does not allow you to turn off editing.

ndugger avatar Jun 07 '16 20:06 ndugger

I need this feature too.

But if you use onOpenChange and ref, you can achieve this feature at the moment.
In the handler function for 'onOpenChange' you should call blur() on the SimpleSelect.

...
onOpenChangeHandler = open => { if (!open) this.refs.theSimpleSelect.blur() }
...
<SimpleSelect 
  ...
  ref='theSimpleSelect'
  onOpenChange={this.onOpenChangeHandler}
  ...
>

proddam avatar Aug 11 '16 05:08 proddam

@proddam how do you keep the dropdown open using your workaround? As soon as I .blur() the select it closes the options menu.

Vpr99 avatar Aug 18 '16 14:08 Vpr99

@Vpr99 Sorry that I don't know how to keep the menu open after .blur() has been called.

proddam avatar Aug 21 '16 00:08 proddam

hack that is currently working for me in my react-redux app (but only tested in Chrome):

// JSX
<SimpleSelect
    ...
    search = ""    
    onValueChange={props.handleSimpleSelectChange}
    ...
/>

...

const mapDispatchToProps = ( dispatch ) => ( { 
    handleSimpleSelectChange: ( selectedValue ) => {
        // guard against backspace
        if ( selectedValue !== undefined ) {  
            // logic
        }
    }
} );

/* css */
input {
    height: 0;
    margin: 0 !important;
    padding: 0 !important;
}

PhilR8 avatar Nov 30 '16 20:11 PhilR8

@PhilR8 oh....thank you! you saved my time!

modestguy avatar Jul 13 '18 13:07 modestguy