Created
October 12, 2015 06:07
-
-
Save mathfarmer/17d8d57e2b384a86ecba to your computer and use it in GitHub Desktop.
Devcards 0.2.0-3 & Reagent 0.5.1 issue: Input box loses focus when typing if atom passed to card
This file contains 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
(ns devcards-react-test.core | |
(:require | |
[reagent.core :as reagent] | |
[sablono.core :as sab :include-macros true]) | |
(:require-macros | |
[devcards.core :as dc :refer [defcard deftest]])) | |
;; -------------------------------------------------- | |
;; This replaces the core.cljs from devcards-template | |
;; Make sure to add [reagent "0.5.1"] to project.clj | |
;; -------------------------------------------------- | |
(enable-console-print!) | |
(defonce shared-state-atom (reagent/atom "foo")) | |
(defonce other-state-atom (reagent/atom "bar")) | |
;; Reagent code copied (with slight modification) from | |
;; http://reagent-project.github.io | |
(defn atom-input [value] | |
[:input {:type "text" | |
:value @value | |
:on-change #(reset! value (-> % .-target .-value))}]) | |
(defn shared-state [] | |
(let [val shared-state-atom] | |
(fn [] | |
[:div | |
[:hr] | |
[:p "The value is now: " @val] | |
[:p "Change it here: " [atom-input val]]]))) | |
(defcard reagent-without-atom | |
"Reagent devcard that doesn't pass the atom to defcard. | |
Editing this works fine." | |
(dc/reagent shared-state)) | |
(defcard reagent-with-atom | |
"Reagent devcard that passes its atom to defcard. | |
Editing this loses focus on each keystroke." | |
(dc/reagent shared-state) | |
shared-state-atom | |
{:inspect-data true | |
:frame true | |
:history true}) | |
(defcard reagent-with-other-atom | |
"Reagent devcard that passes a different atom to defcard. | |
Editing this works fine." | |
(dc/reagent shared-state) | |
other-state-atom | |
{:inspect-data true | |
:frame true | |
:history true}) | |
(defn main [] | |
;; conditionally start the app based on wether the #main-app-area | |
;; node is on the page | |
(if-let [node (.getElementById js/document "main-app-area")] | |
(js/React.render (sab/html [:div "This is working"]) node))) | |
(main) | |
;; remember to run lein figwheel and then browse to | |
;; http://localhost:3449/cards.html | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment