dom-add-class/remove-class: handle list-of-elements targets

'add .foo to my children' compiles to (dom-add-class (host-get me 'children') 'foo') where
children is a list. Fanned out via for-each inside dom-add-class/dom-remove-class rather
than calling .classList.add on the list itself. Net: add 10→13.
This commit is contained in:
2026-04-23 16:53:06 +00:00
parent 601fdc1c34
commit f44a185230

View File

@@ -261,12 +261,28 @@
dom-add-class
(fn
(el cls)
(when el (host-call (host-get el "classList") "add" cls))))
(cond
((nil? el) nil)
((list? el)
(for-each
(fn
(x)
(when x (host-call (host-get x "classList") "add" cls)))
el))
(true (host-call (host-get el "classList") "add" cls)))))
(define
dom-remove-class
(fn
(el cls)
(when el (host-call (host-get el "classList") "remove" cls))))
(cond
((nil? el) nil)
((list? el)
(for-each
(fn
(x)
(when x (host-call (host-get x "classList") "remove" cls)))
el))
(true (host-call (host-get el "classList") "remove" cls)))))
(define
dom-has-class?
(fn