diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index 214830c..416f27d 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -122,14 +122,18 @@ ;; Merge classes class (assoc :class (let [old-class (:class props)] - (if (nil? old-class) class (str class " " (name old-class)))))))) + (if (nil? old-class) class (str class " " (if (named? old-class) + (name old-class) + 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) + (keep (fn [c] + (if c + (if (named? c) + (name c) + c)))) (string/join " ") (assoc props :class)) props)) diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index e1b8736..d965935 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -574,19 +574,24 @@ (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"}]))) +(deftest class-different-types + (testing "named values are supported" + (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" + (testing "non-named values like numbers" + (is (= (rstr [:p {:class [1 :b]}]) + (rstr [:p {:class "1 b"}])))) + + (testing "falsey values are filtered from collections" (is (= (rstr [:p {:class [:a :b false nil]}]) (rstr [:p {:class "a b"}])))) )