use .classList.toggle instead of add / remove

if toggle is undefined, `.toggle` will act as a flip flop (wich the name "toggle" should imply)
if toggle is true, it will add the class unless it is already contained
if toggle is false, it will remove the class unless it is already removed

alternatively i'd probably suggest renaming it from toggle_class to something else. a toggle is a state aware flip flop by default.

any objections?
pull/3189/head
Jan-Stefan Janetzky 6 years ago committed by GitHub
parent 943c04834a
commit b5b8fb1e3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -247,8 +247,8 @@ export function add_resize_listener(element, fn) {
};
}
export function toggle_class(element, name, toggle) {
element.classList[toggle ? 'add' : 'remove'](name);
export function toggle_class(element: Node, name: string, toggle?: boolean) {
element.classList.toggle(name, toggle);
}
export function custom_event<T=any>(type: string, detail?: T) {

Loading…
Cancel
Save