segmentio / evergreen

🌲 Evergreen React UI Framework by Segment
https://evergreen.segment.com
MIT License
12.39k stars 832 forks source link

SelectMenu, if "selected" array changes exterally, previosely selected items emit "onDeselect" on click #1212

Closed psiho closed 3 years ago

psiho commented 3 years ago

CodeSnbox is here: https://codesandbox.io/s/gifted-dan-tiyhl

Open menu, select all options, then click "reset state to cucomber" button in the title.... visually all seems ok, but now click on Apple. Nothing happens because (check console), event "onDeselect" is emitted even if Apple is not selected.

derekvelzy commented 3 years ago

I believe this is because the setSelectedItemNames function is never triggered on the reset button click event.

Here's a CodeSandbox where I use a handleReset function to trigger both the setSelectedItems and setSelectedItemNames. I also moved the functions above the return statement for some cleanup.

CodeSandbox: https://codesandbox.io/s/stupefied-sea-sunnk?file=/index.js

mshwery commented 3 years ago

This is resolved in latest (v6.2.0): https://codesandbox.io/s/quizzical-worker-70tvd