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

Allow toggling classes via a boolean value #11741

Closed
DartBot opened this issue Jul 8, 2013 · 6 comments
Closed

Allow toggling classes via a boolean value #11741

DartBot opened this issue Jul 8, 2013 · 6 comments
Assignees
Labels
web-libraries Issues impacting dart:html, etc., libraries
Milestone

Comments

@DartBot
Copy link

DartBot commented Jul 8, 2013

This issue was originally filed by @seaneagan


Often one has a dynamic bool which specifies whether an element should have a given class. For example, a widget's isActive property could map to an 'active' css class. This use case could be supported by adding an optional argument to CssClassSet.toggle as follows:

void toggle(String clazz, [bool contain]) {
  if(contain == null) contain = !contains(clazz);
  contain ? (add : remove)(clazz);
}

I suppose it should probably be added to toggleAll as well, or maybe just remove toggleAll, since one can do:

classes.forEach(el.toggle);

or:

classes.forEach((clazz) => el.toggle(clazz, contain);

@iposva-google
Copy link
Contributor

Added Area-HTML, Triaged labels.

@blois
Copy link
Contributor

blois commented Jul 10, 2013

Agree that this is more useful than the current toggle.


cc @efortuna.
Added this to the M6 milestone.
Added jquery label.

@efortuna
Copy link
Contributor

Set owner to @efortuna.

@efortuna
Copy link
Contributor

fixed in r24938


Added Fixed label.

@DartBot
Copy link
Author

DartBot commented Jul 19, 2013

This comment was originally written by @sethladd


Thanks Emily, this is cool!

@DartBot
Copy link
Author

DartBot commented Jul 19, 2013

This comment was originally written by @sethladd


For those following along at home, with this patch you can now do:

query('#id').classes.toggle('important', true);

don't forget, you can also do:

query('#id').classes.toggle('important'); which adds if it's not there, and removes if it is there.

@DartBot DartBot added Type-Defect web-libraries Issues impacting dart:html, etc., libraries labels Jul 19, 2013
@DartBot DartBot added this to the M6 milestone Jul 19, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

5 participants