            :width          width
            :height         height
            :placeholder    placeholder
-           :on-change #(do (swap! state-atom assoc :model %)
+           :on-change #(do (swap! state-atom assoc :input-text %)
                            (put! c-input %))
            :change-on-blur? false
-           :model (or model "")
            :attr {:on-key-up   #(on-key-up state-atom %)
                   :on-key-down #(on-key-down state-atom %)}]
           (if (or (not-empty suggestions) waiting?)

  (when-let [key (keys-by-code (.-which event))]
    (.preventDefault event)
    (case key
      :tab   (swap! state-atom suggestion-select-next)
      true)))

(defn- typeahead
  "Returns markup for a typeahead text input"
  [& {:keys [model data-source] :as args}]
  {:pre [(validate-args-macro typeahead-args-desc args "typeahead")]}
  (let [{:as state :keys [ c-search c-sugg c-input c-keypress ]} (make-typeahead-state)
        state-atom (reagent/atom state)]
    (handle-search-results state-atom c-sugg)
    (handle-search state-atom c-sugg data-source c-search)
    (fn
      [& {:keys [model placeholder width height status-icon? status status-tooltip disabled? class style]
          :as   args}]
      {:pre [(validate-args-macro typeahead-args-desc args "typeahead")]}
      (let [{:keys [suggestions waiting? model suggestion-selected-index]} @state-atom
            width (or width "250px")]
        [v-box
         :width width
         :children
         [[input-text
           :class          class
           :style          style
           :disabled?      disabled?

  [state-atom c-sugg]
  (go-loop []
    (let [[search suggestions] (<! c-sugg)]
      (when (= search (:input-text @state-atom))
        (swap! state-atom #(-> %
                               (assoc :suggestions suggestions :waiting? false)
                               select-reset))))
    (recur)))

(defn- make-typeahead-state
  [on-change]
  (let [c-input (chan)]
    (assoc typeahead-state-initial
           :on-change on-change
           :c-keypress (chan)
           :c-input c-input
           :c-search (debounce c-input 250) ;; FIXME hard-coded
