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

Change liSelectedClass background color for each option #251

Closed
paul-brenner opened this issue Jul 12, 2023 · 1 comment · Fixed by #252
Closed

Change liSelectedClass background color for each option #251

paul-brenner opened this issue Jul 12, 2023 · 1 comment · Fixed by #252
Labels
enhancement New feature or request style Anything CSS related

Comments

@paul-brenner
Copy link

paul-brenner commented Jul 12, 2023

First of all, I'd like to express my appreciation for your kind words on the Svelte-multiselect project. Your support means a lot!

I understand you're trying to assign different background colors to each selected item in the Multiselect component. Unfortunately, the liSelectedClass prop isn't designed to directly take dynamic values like option.color. However, there might be a way to achieve the effect you're after.

You've already noticed that Svelte allows you to manipulate the components within the selected item. Building on this, we can use CSS-in-JS to dynamically style each selected item's background color.

Here's a conceptual example on how to do it:

<MultiSelect
	options={locationOptions}
	name="location"
	let:option
	{liSelectedClass}
>
	<div style="background-color: {option.color};">
		{option.label}
	</div>
</MultiSelect>

In this example, I've added a div inside the MultiSelect component, and used inline styles to dynamically set its background color to option.color. This should ensure each selected item has a different background color according to the color property of each option.

As for the showcase site you mentioned (https://openbook.fyi/), it's possible that they were working within the framework's capabilities and decided to use the default gray background color.

Please note that the provided code is a conceptual example. The actual code might need adjustments based on your exact scenario and requirements.

Finally, the image link you've shared seems to be incorrect or broken, as it leads to a 404 Not Found page. Please check the URL and share the correct one if necessary.

I hope this helps! If you have any further questions, please feel free to ask.

@paul-brenner paul-brenner added the bug Something isn't working label Jul 12, 2023
@janosh janosh added enhancement New feature or request style Anything CSS related and removed bug Something isn't working labels Jul 12, 2023
@janosh
Copy link
Owner

janosh commented Jul 12, 2023

Thanks for bringing this up! You can pass --sms-selected-bg="blue"

<MultiSelect {options} --sms-selected-bg="blue"

to change the background color of all selected options at once but you're right there's currently no straighforward way to change the background on a per-option basis. Probably the easiest solution is to extend the type ObjectOption to have a style key that's used as inline CSS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request style Anything CSS related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants