hoist-react icon indicating copy to clipboard operation
hoist-react copied to clipboard

Select with `enableMulti: true` should have option to emit `[]` as value when empty

Open amcclain opened this issue 2 years ago • 2 comments

Currently our select input emits null when empty, as is standard. However when enableMulti is true, it might be more natural / expect (or even required by APIs) to emit [] when empty, so you are always dealing with the bound value as a collection.

This could be an opt-in feature to avoid breaking any existing usages, and to maintain the default behavior of empty === null.

amcclain avatar Feb 15 '23 14:02 amcclain

I'm thinking that a new emptyValue prop on select might be the most generally useful. Default would be null.

We could allow the developer to set any value they wish, regardless of the enableMulti setting. In the prop's doc comment we could clarify that the primary / expected use case is to set it to [] for multi-selects where that is desired, but perhaps there would be some app-specific use for setting it to another value like false or 0.

amcclain avatar Jun 01 '23 21:06 amcclain