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

feat:Inline view of selected options of Multiselect #7287

Merged
30 changes: 20 additions & 10 deletions src/Components/Form/MultiSelectMenuV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ const MultiSelectMenuV2 = <T, V>(props: Props<T, V>) => {
if (selectedOptions.length === 0) return placeholder;
if (props.renderSelectedOptions)
return props.renderSelectedOptions(selectedOptions.map((o) => o.option));
return (
<span className="text-gray-800">{`${selectedOptions.length} item(s) selected`}</span>
);
};

return (
Expand All @@ -89,17 +86,30 @@ const MultiSelectMenuV2 = <T, V>(props: Props<T, V>) => {
<p className="ml-2.5 text-sm font-normal text-gray-600">
<Placeholder />
</p>

{selectedOptions.length !== 0 && (
<div className="flex flex-wrap gap-2 p-2">
{selectedOptions.map((option) => (
<MultiSelectOptionChip
key={option.value}
label={option.selectedLabel}
onRemove={() => {
const updatedOptions = selectedOptions.filter(
(selectedOption) =>
selectedOption.value !== option.value
);
props.onChange(
updatedOptions.map((o) => o.value) as any
);
}}
/>
))}
</div>
)}
</div>
<CareIcon className="care-l-angle-down -mb-0.5 text-lg text-gray-900" />
</div>
</Listbox.Button>
{selectedOptions.length !== 0 && (
<div className="flex flex-wrap gap-2 p-2">
{selectedOptions.map((option) => (
<MultiSelectOptionChip label={option.selectedLabel} />
))}
</div>
)}
</div>
<DropdownTransition show={open}>
<Listbox.Options className="cui-dropdown-base absolute top-12">
Expand Down
Loading