primefaces / primereact

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

MultiSelect: is `valueTemplate` missing? #7137

Closed AlexanderZeilmann closed 2 months ago

AlexanderZeilmann commented 2 months ago

Describe the bug

The MultiSelect template documentation mentions a valueTemplate property. However, it seems that it is not implemented for MultiSelect (it is for Dropdown).

See here for a demo: https://stackblitz.com/edit/vitejs-vite-hmrctz?file=src%2FApp.tsx

Reproducer

https://stackblitz.com/edit/vitejs-vite-hmrctz?file=src%2FApp.tsx

System Information

System info (in Stackblitz)

  System:
    OS: Linux 5.0 undefined
    CPU: (5) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    primereact: latest => 9.5.0 
    react: ^18.2.0 => 18.2.0 

Steps to reproduce the behavior

  1. Implement the valueTemplate as mentioned in the MultiSelect docs.
  2. Typescript shows an error, template is not applied. Bildschirmfoto 2024-09-09 um 08 51 32

Expected behavior

MultiSelect should implement valueTemplate similar to the Dropdown component.

melloware commented 2 months ago

Yep definitely looks like its missing.

AlexanderZeilmann commented 2 months ago

I just noticed that there is selectedItemTemplate which is called for each selected item: https://github.com/primefaces/primereact/blob/e433da4f24c965cfbb868435825139aeb54200d4/components/lib/multiselect/MultiSelect.js#L857-L871

Since this is not documented, the easiest fix would probably be to change the docs to

Available options and the selected options support templating with itemTemplate and selectedItemTemplate properties respectively. In addition, header, footer and filter sections can be templated as well.

Maybe valueTemplate could be used as template that is only called once for all selectedValues with the selectedItemTemplates as children

melloware commented 2 months ago

Thanks I am updating the Docs for selectedItemTemplate