Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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