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: Can't hide or customize header or items wrapper using stlyed components #7454

Closed
lukzfern opened this issue Nov 28, 2024 · 5 comments
Labels
Status: Needs Reproducer Issue needs a runnable reproducer

Comments

@lukzfern
Copy link

lukzfern commented Nov 28, 2024

Describe the bug

Im trying to do 2 things with the MultiSelect component, hide the header and cusomize the items inside of the wrapper, but seems like the styles im targeting are not working:

<StyledMultiSelect
id="abc"
options={options}
placeholder="Test"
value={selectedValue}
onChange={(e) => setSelectedValue(e.value)}
/>

export const StyledMultiSelect = styled(MultiSelect)({
".p-multiselect-header": { display: "none" },
".p-multiselect-item": { background "red" }
});

none of these are working for me.

Reproducer

demo: https://stackblitz.com/edit/hv8ood?file=src%2FApp.jsx

System Information

"dependencies": {
    "@types/react": "^18.2.38",
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "react-transition-group": "^4.4.5",
    "primereact": "latest",
    "primeicons": "^7.0.0",
    "vite": "latest",
    "@vitejs/plugin-react": "latest",
    "primeflex": "^3.3.1",
    "react-scripts": "5.0.1",
"@emotion/react": "^11.13.3",
    "@emotion/styled": "^11.13.0",
  }

Steps to reproduce the behavior

  1. Start a react project with the library
  2. Try to hide the MultiSelect header using the style selector
  3. Try to style each option in the dropdown using the style selector

Expected behavior

You should be able to hide the header easily and also style the dropdown items using the selector

@lukzfern lukzfern added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 28, 2024
@melloware
Copy link
Member

For styling the items you want itemTemplate see: https://primereact.org/multiselect/#template

Second I can hide the header with this CSS

.p-multiselect-panel .p-multiselect-header {
  display:none;
}

image

@melloware melloware added Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Nov 28, 2024
@melloware melloware closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2024
@lukzfern
Copy link
Author

Yeah that's why I said im using styled components, I can do it with CSS, but as my description says, im using the StyledMultiSelect I created, and even when targeting the correct css styles, they are not applying. My question was because with other components like table, paginator, etc. it works perfectly fine.

@melloware melloware added Status: Needs Reproducer Issue needs a runnable reproducer and removed Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team labels Nov 28, 2024
Copy link

Please fork the Stackblitz project and create a case demonstrating your bug report. This issue will be closed if no activities in 20 days.

@lukzfern
Copy link
Author

@melloware
Copy link
Member

@lukzfern it looks like an EMOTION issue. If you look at the DOM in the inspector the panel does not EXIST when the component is created. It is created and added to the DOM only on popup. So my guess is Emotion doesn't see those in the Dom at Render time so it has nothing to apply. You might have to look at Emotion on how to trigger updating styles when the component re-renders...

A lot of PrimeReact components do this so this won't be your last issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Reproducer Issue needs a runnable reproducer
Projects
None yet
Development

No branches or pull requests

2 participants