From 606b321d2fa31fb8b63efa57ad16b8b6d22a7bae Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Fri, 27 Apr 2018 23:19:59 +0300 Subject: [PATCH] Fix keywords and symbols in :class Fixes #367 --- src/reagent/impl/template.cljs | 4 +++- test/reagenttest/testreagent.cljs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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})