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

selectedState does not exist #637

Closed
St-Permiakov opened this issue Sep 17, 2019 · 14 comments · Fixed by #754
Closed

selectedState does not exist #637

St-Permiakov opened this issue Sep 17, 2019 · 14 comments · Fixed by #754
Labels

Comments

@St-Permiakov
Copy link

Related to #367
As stated there, selectedState css-class does not appear on selected option.
So either documentation is incorrect or it's a bug.

@mroseboom
Copy link

Hey there, any update on this?

@tinovyatkin
Copy link
Contributor

@jshjohnson Do you want that to be implemented or removed from documentation?

@jshjohnson
Copy link
Collaborator

I think it can be removed - I don't see any distinction between this and the highlighted state

@St-Permiakov
Copy link
Author

St-Permiakov commented Oct 25, 2019

It most assuredly cannot.
Highlighted state appears on hover and selected should appear on currently selected (checked) items. Those are completely different use cases.

@jshjohnson
Copy link
Collaborator

@St-Permiakov you could use the 'highlighted' state for that situation

@mroseboom
Copy link

@jshjohnson At this moment it isn't implemented or i'm missing someting?

@tinovyatkin
Copy link
Contributor

@mroseboom it's not implemented in code base in current version.

@St-Permiakov
Copy link
Author

Does it appear on selected item without user hovering it?
How can I distinguish selected item when I'm hovering it?
And what if I'm supposed to make selected item visually disabled (that was my use case actually)?

@tinovyatkin
Copy link
Contributor

@jshjohnson the implementation will be trivial and I can easily add that, however, @St-Permiakov use case probably will anyway require overriding template rendering.

Is that feature were never implemented or were removed in past version without updating documentation?

@St-Permiakov
Copy link
Author

Well, the only reason why I created this issue was impossibility to distinguish hovered and selected states for styling. That's what that selectedState was supposedly for. If there is any other way...

@tinovyatkin
Copy link
Contributor

tinovyatkin commented Oct 30, 2019

@St-Permiakov with Choices 8 released today:

const example = new Choices(element, {
  callbackOnCreateTemplates: () => ({
    item(classes, item) {
      const i = Choices.defaults.templates.item.call(this, classes, item);
      if (item.selected) i.classList.add("is-selected");
      return i;
    },
   // or
    choice(classes, choice) {
      const i = Choices.defaults.templates.choice.call(this, classes, choice);
      if (choice.selected) i.classList.add("is-selected");
      return i;
    }
  })
});

@stasguma
Copy link

@tinovyatkin For me works the second example with a choice function. Thanks a lot.
I'll correct you a little.
In this part classList.add(".is-selected") we don't need a dot before is-selected.

It would be better if it worked without a workaround

@tinovyatkin
Copy link
Contributor

@stasguma glad it works for you, fixed an example, thank you!

@jshjohnson jshjohnson added the bug label Nov 13, 2019
@jshjohnson jshjohnson mentioned this issue Nov 13, 2019
8 tasks
@jshjohnson
Copy link
Collaborator

I've addressed this bug here: #754 - note only a "choice" has a "selected" state. An item does not 👍

jshjohnson added a commit that referenced this issue Nov 13, 2019
* Add is-selected class when item is selected

* Remove console.log

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

Successfully merging a pull request may close this issue.

5 participants