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

Controlled MultiSelect Acting Up

Open patrickml opened this issue 9 years ago • 17 comments

For some reason when using a controlled multiselect the cursor in the input field gets all sort of messed up. And the values are not removed when you add a tag. https://cl.ly/0E1P0h2h1a1t

code

<MultiSelect
   placeholder="Select Roles"
   options={system && SystemAndRoles[system].map(valueToOptions) || []}
   values={roles && roles.map(valueToOptions) || []}
   disabled={!!!system}
   filterOptions={filterOptions}
   onValuesChange={(options) => sendChange('roles', options.map(o => o.value))}
   transitionEnter
   transitionLeave
   tether
/>

patrickml avatar Jul 14 '16 17:07 patrickml

Not entirely sure about the big picture there, Not able to reproduce the issue here: http://codepen.io/furqanZafar/pen/bZaBBa

furqanZafar avatar Jul 14 '16 18:07 furqanZafar

@furqanZafar I know I am getting a lot of event.persist() errors do you think it could have something to do with that? I know there has been a change for that, that hasn't been pushed to NPM.

patrickml avatar Jul 14 '16 18:07 patrickml

Try release 2.0.3 though I doubt that was causing any serious issues

furqanZafar avatar Jul 14 '16 18:07 furqanZafar

@furqanZafar testing 2.0.3 did fix #80 but it did not help here sadly.

patrickml avatar Jul 14 '16 22:07 patrickml

Update So as seen in the video if i type in Admin it isn't removed from the input -- i just noticed that if i click outside of the component it will then be removed? Any ideas?

patrickml avatar Jul 14 '16 22:07 patrickml

Not sure, could you make a pen or fiddle reproducing this issue?

furqanZafar avatar Jul 15 '16 02:07 furqanZafar

I am wondering if its an issue similar to the React Input issue where when the controlled input is controlled by an outside state i.e. a store and passed as props the cursor moves. For more context I am using the FLUX arch. And storing all the changes in a store which this components parent is subscribed to.

patrickml avatar Jul 15 '16 13:07 patrickml

I had a similar issue when using the multiselect advanced tags example. In my case the search text was not initially removed from the input when it was added. I'd have to click out of the input to clear it. Adding the uid function (unique id) to the multiselect component solved the issue. I overlooked that but it's in the documentation. I wonder if that will help any with your issue?

nikkipurcell avatar Jul 15 '16 23:07 nikkipurcell

Thanks nikkipurcell I was having the exact same issue and was trying to fix it using the search and onSearchChange options (with a strange behavior).. but adding the uid function fixed all.

thombuchi avatar Jul 16 '16 16:07 thombuchi

@nikkipurcell i am basically haveing that same issue i just tried to add the uid use this as a prop uid={(o) => o.value + system} but it didnt seem to work @nikkipurcell @thombuchi what did you do for your uid?

patrickml avatar Jul 16 '16 17:07 patrickml

I just used uid={(item) => return item.value} and all started working like a charm.

thombuchi avatar Jul 16 '16 19:07 thombuchi

Can somebody explain that on what depends if the search is cleared after selecting an element from the drowdown list on the MultiSelect component?

I'm using 2.0.3 and I have a MultiSelect component for which there is a predefined option list but you can also create new "tags" and everything is working well, except that when I type in some characters into the searchbar and then select an option from the menu (or create a new tag) the search doesn't get cleared.

I tried to debug it, but I only found out that here: https://github.com/furqanZafar/react-selectize/blob/master/src/ReactSelectize.ls#L504 the @props.values does not contain the newly added tag so that find is bound to fail.

I also tried using the uid property but didn't solve it.

gergely-ujvari avatar Aug 10 '16 14:08 gergely-ujvari

Ok, I found out what was my problem. Adding the initial values triggered this behavior. There is a contradiction between the documentation and the examples. For the Multiselect API it says it has a defaultValues property but all the examples use the values property instead which is also working but triggers this side-effect I explained above.

gergely-ujvari avatar Aug 10 '16 15:08 gergely-ujvari

@gergely-ujvari if you use defaultValues are you still able to clear the values via state?

patrickml avatar Aug 10 '16 19:08 patrickml

No, not always for some strange reasons. Using backspace to clear an item from the search bar works fine, but I also wanted to add a little x button to all tags to be able to clear them with a click (like in the emoji example) but that doesn't work with defaultValue.

gergely-ujvari avatar Aug 11 '16 12:08 gergely-ujvari

These comments finally helped me to get my MultiSelect working correctly. I wanted to have an "X" to remove options onClick as shown in the emoji example and as mentioned in several issues here.

I added a renderValues function. For me it only worked after using values instead of defaultValues. This is not well documented so I wasted a lot of hours on tracking this down.

I would suggest providing a better documentation/example for this use case. I feel a lot of people want to have a standard MultiSelect with an X button on each option.

stizzlestizzle avatar Jan 16 '17 10:01 stizzlestizzle

FWIW I was seeing same behavior as OP and it was fixed (as suggested previously) by adding

uid={(i) => i.label}

to the component invocation.

jamesob avatar Oct 19 '17 00:10 jamesob