Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify when should InputPicker display "Create option" action #3267

Closed
SevenOutman opened this issue Jun 27, 2023 · 0 comments · Fixed by #3270
Closed

Specify when should InputPicker display "Create option" action #3267

SevenOutman opened this issue Jun 27, 2023 · 0 comments · Fixed by #3270

Comments

@SevenOutman
Copy link
Member

What problem does this feature solve?

Most of the time when we use a creatable InputPicker, we don't want user to create a new option with duplicated name with existing entries.

image

For now InputPicker hides "Create option" action when the search keyword matches any entry's [valueKey], which is not ideal IMO. Instead we tend to avoid duplicated [labelKey] most of the time.

if (creatable && searchKeyword && !items.find(item => item[valueKey] === searchKeyword)) {
items = [...items, createOption(searchKeyword)];
}

What does the proposed API look like?

Provide a new prop for users to specify whether to display "Create option" action with given keyword. Something like:

type InputPickerProps = {
  shouldDisplayCreateOption?: (keyword: string, data: T[]) => boolean;
}

Usage example:

<InputPicker
  shouldDisplayCreateOption={(keyword, data) => {
    return data.every(item => item.name !== keyword)
  }}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant