primefaces / primereact

The Most Complete React UI Component Library
https://primereact.org
MIT License
6.9k stars 1.05k forks source link

Dropdown: Creatable #6805

Closed franmc01 closed 4 months ago

franmc01 commented 4 months ago

Describe the feature

image

Is it possible that the editable version enables something like creating an option if it does not exist?

Reproducer

No response

PrimeReact version

latest

React version

18.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

sja-cslab commented 4 months ago

Did you see the Autocomplete Dropdown? Maybe you can use this

franmc01 commented 4 months ago

No, I am referring to a dropdown variant where it is allowed to create options in case it is not in the list. Example:

https://react-select.com/creatable#creatable

melloware commented 4 months ago

@franmc01 what I have seen others do and makes sense from a UI/UX point of view is use the panelFooterTemplate to add a "Add New" button: https://primereact.org/dropdown/#template

so if they don't see their item in the list they click "Add New" and you bring up a dialog to allow them to enter a new value and validate etc. I know in PrimeFaces JSF that is what people do but I have not tested it in PrimeReact.

theart84 commented 2 months ago

I made an implementation like this and it works well

  const onKeyDownAttributeHandler = (event: KeyboardEvent<HTMLInputElement>) => {
    if (event.code === 'Enter') {
      const { value } = event.target;
      const payload = {
        name: value.trim(),
      }
      createAttribute(payload); // rtq hook
    }
  };

It would be cool to have the same option for MultiSelect