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

How to hide selection that isn't active? #267

Open
flatcapco opened this issue Dec 3, 2014 · 1 comment
Open

How to hide selection that isn't active? #267

flatcapco opened this issue Dec 3, 2014 · 1 comment

Comments

@flatcapco
Copy link

I'm not sure if this is an issue or poor understanding by me:
When I use:

showSelectionPalette: true,
maxSelectionSize: 1,

It adds another palette colour after my original palette which is great.. however if I click back to one of the original palette colours it still shows the previous selection after the original palette list.

How do I hide the newly created colour (the one that wasn't in the original palette) if it is no longer active?

In simple terms - if its not active or in the original palette I don't want to see it.

Many thanks for such a great plugin

@bgrins
Copy link
Owner

bgrins commented Dec 7, 2014

The selection palette is designed to keep these colors around for quick reselection of previously used colors. I believe you could do something where on change you update the existing palette to include the currently selected color but only if it isn't in the palette in the first place.

Something like this probably (totally untested but this is the idea):

foo.spectrum({
  palette: [['red'], []],
  change: function(color) {
    var palettes = $(this).spectrum("option", "palette");
    // should probably check here first to make sure this color isn't in the palette already
    palettes[palettes.length - 1] = [color.toHexString()];
    $(this).spectrum("option", "palette", palette);
  }
})

You could also consider using the showInitial option - maybe it is closer to what you are after? https://bgrins.github.io/spectrum/#options-showInitial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants