diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index 73cebef..214830c 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -122,12 +122,14 @@ ;; Merge classes class (assoc :class (let [old-class (:class props)] - (if (nil? old-class) class (str class " " old-class))))))) + (if (nil? old-class) class (str class " " (name old-class)))))))) (defn stringify-class [{:keys [class] :as props}] + ;; (keep name) doesn't work because class vector could contain false, which is not Named (if (coll? class) (->> class (filter identity) + (map name) (string/join " ") (assoc props :class)) props)) diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index 12d69c1..e1b8736 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -574,6 +574,22 @@ (is (= (rstr [:p {:class #{"a" "b" "c"}}]) (rstr [:p {:class "a b c"}])))) +(deftest class-named-values + (is (= (rstr [:p {:class :a}]) + (rstr [:p {:class "a"}]))) + (is (= (rstr [:p.a {:class :b}]) + (rstr [:p {:class "a b"}]))) + (is (= (rstr [:p.a {:class 'b}]) + (rstr [:p {:class "a b"}]))) + (is (= (rstr [:p {:class [:a :b]}]) + (rstr [:p {:class "a b"}]))) + (is (= (rstr [:p {:class ['a :b]}]) + (rstr [:p {:class "a b"}]))) + + (testing "class collection can contain false value" + (is (= (rstr [:p {:class [:a :b false nil]}]) + (rstr [:p {:class "a b"}])))) ) + (deftest test-force-update (let [v (atom {:v1 0 :v2 0})