antizer icon indicating copy to clipboard operation
antizer copied to clipboard

Text cursor jumps to last position for ant/input controllable value

Open amakurin opened this issue 5 years ago • 2 comments

It works fine with html [:input], but for ant/input check this:

(defn example [_]
  (let [state (r/atom {:title ""})]
    (fn [_]
      [ant/form
       [ant/form-item
        [ant/input
         {:value       (:title @state)
          :on-change   (fn [e] (swap! state assoc :title (.. e -target -value)))
          :placeholder "Title"}]]])))

amakurin avatar Mar 04 '19 11:03 amakurin

Hello. According to Antd docs you can use defaultValue attribute not value. Maybe Input component handle changing state automatically (I don't see value attribute in docs).

mishazawa avatar Mar 13 '19 16:03 mishazawa

Did you look here? https://ant.design/components/input/

defaultValue | The initial input content | string | ... value | The input content value | string ...

When Input is used in a Form.Item context, if the Form.Item has the id and options props defined then value, defaultValue, and id props of Input are automatically set.

-- So example looks correct for me.

amakurin avatar Mar 13 '19 19:03 amakurin