tremor icon indicating copy to clipboard operation
tremor copied to clipboard

Enhancement Request: Missing onChange Event and Server Data Search in SelectBox API

Open sendistephen opened this issue 2 years ago • 5 comments

I would like to request an enhancement for the SelectBox API. Currently, I have noticed that there is no onChange event available, and I am unable to perform server data searches using the SelectBox component. Search only works on the client

sendistephen avatar May 10 '23 16:05 sendistephen

There is onValueChange event handler which I assume is you are looking for.

amirhhashemi avatar May 11 '23 06:05 amirhhashemi

Currently, the onValueChange event in the SelectBox only provides the value of the SelectedBoxItem. However, I would like to discuss the possibility of adding an onInputChange event to handle input change events on the SelectBox.

Allow me to illustrate this with an example. Let's say I have an array of tag data obtained from an API. Due to pagination limitations, the API only returns 10 tags per request. However, I want to be able to search for tags on the server. Unfortunately, the current implementation of the SelectBox does not offer a way to achieve this.

If an onInputChange event were available, I could easily type in the SelectBox and have the input value(string) sent to the API for searching purposes.

Here's a code snippet demonstrating the current usage of the SelectBox:

   <SelectBox value={selected} onValueChange={(value) => setSelected(value)}>
           {tags?.map((tag) => (
             <SelectBoxItem key={tag.id} value={tag.id} text={tag.label} />
           ))}
    </StyledSelectBox>

sendistephen avatar May 11 '23 15:05 sendistephen

@sendistephen, thanks for the suggestion. I see the point and think it may be useful in certain cases. The thing is that currently, we cover the entire filtering logic on the client and don't allow for custom filtering (that you could then perform on the server as well). As you noted the onValueChange handler does only reference the currently selected value. A potential implementation would be to add a onInputValueChange handler that "disables" the internal filtering logic and passes that responsibility to the user. Would something like this make sense? We will keep this in mind for our roadmap.

mitrotasios avatar May 11 '23 15:05 mitrotasios

Seconding this feature request. The inability to detect onInputValueChange is preventing me from using the SelectBox, and as a workaround I had to make my own SelectBox in order to detect what the user is typing. (My use case is that the SelectBox needs to load in tens of thousands of options, which is too many to do at once, so I need to detect the user input and dynamically load in the options).

rebasedming avatar May 19 '23 20:05 rebasedming

This is an important feature for large datasets, where filtering on the client side is not a good practice. This feature is essential for my project too and it would be incredible to have it available

juanmarin-co avatar Jul 23 '23 05:07 juanmarin-co