alsoscotland / react-super-select

MIT License
95 stars 33 forks source link

How to clear selection programatically? #121

Closed prdebski closed 7 years ago

prdebski commented 7 years ago

How can I clear selection programatically? I need to do it by clicking a button not being part of select. Setting initialValue prop to undefined does not work.

alsoscotland commented 7 years ago

@prdebski My apologies for the delay. Started a new job last week. at present you cannot do this. I will try and investigate adding the initialValue to what is inspected when props update. I am not sure what the level of complication in doing so without looking into it

alsoscotland commented 7 years ago

@prdebski Finally got some time to start looking at this. I am checking for initial value change when props update so I am not certain why this is not working yet. Should have an answer for you fairly soon

alsoscotland commented 7 years ago

@prdebski I was able to get a test scenario up and for me when I set initialValue to undefined I see the control clear. I am not able to reproduce a problem. Can you possibly give me more info about what is going on?

alsoscotland commented 7 years ago

@prdebski Going to close for now as I was unable to reproduce the issue

6079-Smith-W commented 3 years ago

I'm still struggling with what I think @prdebski was struggling with - I can't figure a way to programmatically clear three super-selects on my form along with all the other options (This may be because I'm doing something obviously and glaringly wrong, though). I did set 'initialValue' to a property of a react state hook object:

    const defaultQuery = {
        startDate: "",
        endDate: "",
           ...
        status: { key: 0, statusdisp: 'Active', statusvalue: 0 }
    };
    const [formData, setForm] = useState(defaultQuery);
    ...
    <react-super-select ...
    initialValue={formData.status}
    ...
    />

Changing formData with setForm(), like setForm(defaultQuery) or setForm({...formData, status: undefined}) does not reset the form as I'd expect - should it continue to reference and update the super-select when initialValue is modified? That's what seems to work with other controls I've downloaded (inherited from previous developers that knew more than me but are not available to ask right now) - I'm unsure if it's the control is lacking the capability or if I'm not actually telling it what to do correctly...

Again, I may be missing something obvious - I hope I am, so it will be easy for you to give me a solution

alsoscotland commented 3 years ago

@6079-Smith-W Thanks for reaching out. I have not had bandwidth to work on this component for several years now. It was last compatible with React@15.x.x which was before hooks. I am not sure how it would interact in current react with hooks

6079-Smith-W commented 3 years ago

It was last compatible with React@15.x.x which was before hooks. I am not sure how it would interact in current react with hooks

Thanks - I think we'll just go ahead and use react-select, which was already included in my project, but my lack of experience and guidance led me to go down a path with a little less activity/community than I probably should have, to get functionailty I didn'e realize was already in react-select from another control.