From b4ec13f003d560b98724ec24299cc3159ef0503a Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Tue, 13 Sep 2016 15:15:39 +0300 Subject: [PATCH 1/2] Fix #259: Call original ref in ReagentInput --- src/reagent/impl/template.cljs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index fc6b0c2..9d907fa 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -174,7 +174,8 @@ (.hasOwnProperty jsprops "value")) (let [v ($ jsprops :value) value (if (nil? v) "" v) - on-change ($ jsprops :onChange)] + on-change ($ jsprops :onChange) + original-ref ($ jsprops :ref)] (when (nil? ($ this :cljsInputElement)) ;; set initial value ($! this :cljsDOMValue value)) @@ -183,7 +184,9 @@ (doto jsprops ($! :defaultValue value) ($! :onChange #(input-handle-change this on-change %)) - ($! :ref #($! this :cljsInputElement %1)))))) + ($! :ref (fn [el] + (if original-ref (original-ref el)) + ($! this :cljsInputElement el))))))) (defn ^boolean input-component? [x] (case x From 0303c6ddeff10a5da22d36f0c374b116f53f2cdf Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Wed, 14 Sep 2016 23:10:02 +0300 Subject: [PATCH 2/2] Use findDOMNode instead of ref to manage ReagentInput --- src/reagent/impl/template.cljs | 12 ++++-------- src/reagent/impl/util.cljs | 7 +++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index 9d907fa..f0e1c48 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -109,7 +109,7 @@ (contains? these-inputs-have-selection-api input-type)) (defn input-set-value [this] - (when-some [node ($ this :cljsInputElement)] + (when-some [node ($ util/react-dom findDOMNode this)] ($! this :cljsInputDirty false) (let [rendered-value ($ this :cljsRenderedValue) dom-value ($ this :cljsDOMValue)] @@ -174,19 +174,15 @@ (.hasOwnProperty jsprops "value")) (let [v ($ jsprops :value) value (if (nil? v) "" v) - on-change ($ jsprops :onChange) - original-ref ($ jsprops :ref)] - (when (nil? ($ this :cljsInputElement)) + on-change ($ jsprops :onChange)] + (when (nil? ($ this :cljsDOMValue)) ;; set initial value ($! this :cljsDOMValue value)) ($! this :cljsRenderedValue value) (js-delete jsprops "value") (doto jsprops ($! :defaultValue value) - ($! :onChange #(input-handle-change this on-change %)) - ($! :ref (fn [el] - (if original-ref (original-ref el)) - ($! this :cljsInputElement el))))))) + ($! :onChange #(input-handle-change this on-change %)))))) (defn ^boolean input-component? [x] (case x diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index 0d9d4cc..e231c7d 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -10,6 +10,13 @@ (throw (js/Error. "require('react') failed"))) :else (throw (js/Error. "js/React is missing")))) +(defonce react-dom + (cond (exists? js/ReactDOM) js/ReactDOM + (exists? js/require) (or (js/require "react-dom") + (throw (js/Error. "require('react-dom') failed"))) + :else + (throw (js/Error. "js/ReactDOM is missing")))) + (def is-client (and (exists? js/window) (-> js/window ($ :document) nil? not)))