When searchable and one or more of searchProps.onChange and searchProps.onSearch is passed to EuiSelectable, the options are not correctly filtered in the UI. I created a sandbox showing both issues.
I believe in both cases the searchProps are being spread over more important props, which seems unintended.
onChange={this.onSearchChange} appears to be key to updating the selectable internal state{...cleanedSearchProps} overrides itI'm less sure about the cause of this issue, but have a feeling it could be:
onSearch can exist in ...rest (which comes from cleanedSearchProps above), overriding the important call to this.onSearchChangeThe feature I'm working on extends the EuiSelectable component, by adding "Select all" and "Select none" buttons above the searchable EuiSelectable. Here's an example of the UI.
This works without any hassle. I update the local options state when a user clicks on either button, and pass this state down to EuiSelectable. After building this, I realized that it would be a better UX to combine this behaviour with the client-side search offered by adding searchable. In my current implementation the user could filter (let's say to view 5 of 100 items), then click "Select all". This would select not only the visible/filtered options, but all of them.
To fix this UX issue, I tried to access the currently filtered items. I found I could do this as shown:
searchProps={{
onChange: (filteredOptions) => {
// here I set some local state. Implementation details not important.
},
}}
Elsewhere, I could use this data to compare the filteredOptions and options, and work out which options should be updated when a user clicks on one of the Select all/none buttons. Again, no problems here.
I believe the data-flow is working fine using the existing props, and the only issue is that my combination of props prevents the EuiSelectable from accurately reflecting the search filters in the UI.
Thanks for the investigation, @smhutch
It seems like your assessment is correct. We should be calling searchProps.onChange and searchProps.onSearch in addition to the "standard" onChange and onSearch callbacks.
Fixed in #4153