Created
November 26, 2018 18:43
-
-
Save mrrodriguez/721963b37e8afc53ce6d06b8e58907ff to your computer and use it in GitHub Desktop.
Reagent input cursor jumping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; Dealing with jumping cursors on controlled input (a classic React/Reagent problem). | |
;;;; For rationale see | |
;;;; https://github.com/reagent-project/reagent/issues/265#issuecomment-397895508 | |
;;;; & | |
;;;; https://github.com/reagent-project/reagent/blob/e53be656073af9209c4fe8bc9119635953311d42/examples/material-ui/src/example/core.cljs#L34 | |
;; In the ns header... | |
(:require [reagent.core :as r] | |
[reagent.impl.template :as template]) | |
(def ^:private input-component | |
(r/reactify-component | |
(fn [props] | |
[:input (-> props | |
(assoc :ref (:inputRef props)) | |
(dissoc :inputRef))]))) | |
(defn SafeTextField [base-input props & children] | |
(let [props (-> props | |
(assoc :componentClass input-component) | |
template/convert-prop-value)] | |
(apply r/create-element | |
base-input | |
props | |
(map r/as-element children)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment