Skip to content

Instantly share code, notes, and snippets.

@mrrodriguez
Created November 26, 2018 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrrodriguez/721963b37e8afc53ce6d06b8e58907ff to your computer and use it in GitHub Desktop.
Save mrrodriguez/721963b37e8afc53ce6d06b8e58907ff to your computer and use it in GitHub Desktop.
Reagent input cursor jumping
;;;; 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