Skip to content

Commit

Permalink
Handle nil in interpreter/atributes (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
r0man committed Mar 26, 2017
1 parent 1e8c0ad commit 1b7a190
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
* Changelog
** Unreleased
- [[https://github.com/r0man/sablono/issues/158][#158]] Fix camel-case bug in :style attributes.
- [[https://github.com/r0man/sablono/issues/158][#158]] Fix camel-case bug in :style attributes and handle nil in =interpreter/atributes=.
- [[https://github.com/r0man/sablono/pull/152][#152]] Don't coerce nil/undefined input :value to be consistent with React.
- [[https://github.com/r0man/sablono/pull/149][#149]] Force lazy seq in interpret-seq to be realized.
- [[https://github.com/r0man/sablono/pull/146][#146]] Keep state and props of inputs synchronized.
Expand Down
14 changes: 7 additions & 7 deletions src/sablono/interpreter.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@

#?(:cljs
(defn attributes [attrs]
(let [js-attrs (clj->js (util/html-to-dom-attrs attrs))
class (.-className js-attrs)
class (if (array? class) (join " " class) class)]
(if (blank? class)
(js-delete js-attrs "className")
(set! (.-className js-attrs) class))
js-attrs)))
(when-let [js-attrs (clj->js (util/html-to-dom-attrs attrs))]
(let [class (.-className js-attrs)
class (if (array? class) (join " " class) class)]
(if (blank? class)
(js-delete js-attrs "className")
(set! (.-className js-attrs) class))
js-attrs))))

(defn- interpret-seq
"Interpret the seq `x` as HTML elements."
Expand Down
7 changes: 7 additions & 0 deletions test/sablono/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,4 +1307,11 @@
{:tag :div
:attributes
{:style "margin-left:2rem;color:red;"}
:content []})))
(let [focused? false]
(is (= (html-data [:div {:style (merge {:margin-left "2rem"}
(when focused? {:color "red"}))}])
{:tag :div
:attributes
{:style "margin-left:2rem;"}
:content []}))))
1 change: 1 addition & 0 deletions test/sablono/interpreter_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
(deftest test-attributes
(are [attrs expected]
(= expected (js->clj (i/attributes attrs)))
nil nil
{} {}
{:className ""} {}
{:className "aa"} {"className" "aa"}
Expand Down

0 comments on commit 1b7a190

Please sign in to comment.