hc-oss / react-multi-select-component

Lightweight (~5KB gzipped) multiple selection dropdown component
https://codesandbox.io/s/react-multi-select-example-uqtgs
MIT License
386 stars 89 forks source link

`defaultIsOpen` feature does not work when combined with `closeOnChangedValue` #718

Open BentleyDavis opened 12 months ago

BentleyDavis commented 12 months ago

Description the bug defaultIsOpen feature does not work when combined with closeOnChangedValue

Sandbox / Git Repo https://codesandbox.io/s/defaultisopen-and-closeonchangedvalue-q4mrsd

To Reproduce Steps to reproduce the behavior:

  1. Set the option defaultIsOpen={true}
  2. Render and see it open automatically
  3. Set the options closeOnChangedValue={true}
  4. Render and see it no longer opens automatically

Expected behavior The select should stay open until acted on. It opens then quickly shuts before the user can get to it.

Screenshots image

Desktop (please complete the following information):

Smartphone (please complete the following information): N/A

Additional context Looks like in dropdown.tsx line 35 the useEffect closes the select on all renders including the first.

useEffect(() => {
    if (closeOnChangedValue) {
      setExpanded(false);
    }
  }, [value]);