Skip to content

Commit

Permalink
Fix Caret moves to the end when editing a TextArea in reagent #17
Browse files Browse the repository at this point in the history
  • Loading branch information
madvas committed Oct 4, 2016
1 parent 3940435 commit c04f543
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Current Material-UI version: `0.15.4`
https://github.com/madvas/cljs-react-material-ui-example

## Installation
- Add `[cljs-react-material-ui "0.2.22"]` to your dependencies
- Add `[cljs-react-material-ui "0.2.23"]` to your dependencies
- Exclude `cljsjs/react` from Om or other React library.
This is because currently material-ui has to be built together with react to get [onTouchTap](http://www.material-ui.com/#/get-started/installation) event [working](http://stackoverflow.com/questions/29881439/react-tap-events-and-material-ui). This will not be needed in future.
for example: `[org.omcljs/om "1.0.0-alpha34" :exclusions [cljsjs/react]]`
Expand Down Expand Up @@ -129,18 +129,4 @@ Works with `reagent "0.6.0-alpha"` and up. So dependency may be sth like this
[:div
(rui/paper {} "Ima paper")]))]))

```

## Troubleshooting
##### Caret moves to the end when editing a text field
This happens due to async rendering of clojurescript react libraries.
Luckily, there is a workaround, which fixes most of use cases: Instead of `:value` prop use `:default-value` e.g:
```
(defn simple-text-field [text]
(let [text-state (r/atom text)]
(fn []
[rui/text-field
{:id "example"
:default-value @text-state
:on-change (fn [e] (reset! text-state (.. e -target -value)))}])))
```
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject cljs-react-material-ui "0.2.22"
(defproject cljs-react-material-ui "0.2.23"
:description "Iterop library for material-ui.com"
:url "https://github.com/madvas/cljs-react-material-ui"
:license {:name "Eclipse Public License"
Expand Down
10 changes: 9 additions & 1 deletion src/cljs_react_material_ui/reagent.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
(ns cljs-react-material-ui.reagent
(:refer-clojure :exclude [list stepper])
(:require [reagent.core :as r]))
(:require [reagent.core :as r]
[reagent.impl.template]
[reagent.interop :refer-macros [$ $!]]))

(set! reagent.impl.template/input-component?
(fn [x]
(or (= x "input")
(= x "textarea")
(= (reagent.interop/$ x :name) "TextField"))))

(def app-bar (r/adapt-react-class (aget js/MaterialUI "AppBar")))
(def auto-complete (r/adapt-react-class (aget js/MaterialUI "AutoComplete")))
Expand Down

0 comments on commit c04f543

Please sign in to comment.