elachere
elachere

Reputation: 815

Close dropdown on clear

I'm using react-dropdown-select with the clearable option, but when I do clear the dropdown stays open, I'd like it to close once cleared. So far I tried to make a custom Select class and override its clearRenderer() callback prop to make use of the dropDown() method int it, something like that:

class MySelect extends Select {
    clearRenderer = ({ props, state, methods }) => {
        methods.dropDown('close');
    };
}

but I can't get it to work.

I'm new to javascript, I'm probably missing something here, thank's for your help.

Upvotes: 2

Views: 351

Answers (1)

Zachary Haber
Zachary Haber

Reputation: 11027

If you set closeOnSelect on the dropdown, then it will close when you clear it.

If you want it to stay open on a normal select, then this will work: https://codesandbox.io/s/old-glade-l2hkv. What it's doing is in the onClearAll handler, using a ref to call the method in the select component to toggle the dropdown.

Upvotes: 2

Related Questions