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

MultiSelect: is valueTemplate missing? #7137

Closed
AlexanderZeilmann opened this issue Sep 9, 2024 · 3 comments · Fixed by #7143 · May be fixed by leoo1992/GeradorQRCode#95
Closed

MultiSelect: is valueTemplate missing? #7137

AlexanderZeilmann opened this issue Sep 9, 2024 · 3 comments · Fixed by #7143 · May be fixed by leoo1992/GeradorQRCode#95
Assignees
Labels
Component: Documentation Issue or pull request is related to Documentation
Milestone

Comments

@AlexanderZeilmann
Copy link
Contributor

AlexanderZeilmann commented Sep 9, 2024

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.

@AlexanderZeilmann AlexanderZeilmann added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 9, 2024
@melloware melloware added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 9, 2024
@melloware
Copy link
Member

Yep definitely looks like its missing.

@AlexanderZeilmann
Copy link
Contributor Author

I just noticed that there is selectedItemTemplate which is called for each selected item:

if (props.selectedItemTemplate) {
if (!empty) {
if (ObjectUtils.isNotEmpty(props.maxSelectedLabels) && props.value.length > props.maxSelectedLabels) {
return getSelectedItemsLabel();
}
return props.value.map((val, index) => {
const item = ObjectUtils.getJSXElement(props.selectedItemTemplate, val);
return <React.Fragment key={index}>{item}</React.Fragment>;
});
}
return ObjectUtils.getJSXElement(props.selectedItemTemplate);
}

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 added a commit to melloware/primereact that referenced this issue Sep 9, 2024
@melloware melloware added Component: Documentation Issue or pull request is related to Documentation and removed Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add labels Sep 9, 2024
@melloware melloware self-assigned this Sep 9, 2024
@melloware melloware added this to the 10.8.3 milestone Sep 9, 2024
@melloware
Copy link
Member

Thanks I am updating the Docs for selectedItemTemplate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Documentation Issue or pull request is related to Documentation
Projects
None yet
2 participants