 (defn- handle-search-results
   [state-atom c-sugg]
   (go-loop []
-    (let [[search suggestions] (<! c-sugg)]
-      (when (= search (:input-text @state-atom))
+    (let [[search suggestions] (<! c-sugg)
+          {:keys [input-text]} @state-atom]
+      (when (= search input-text)
         (swap! state-atom #(-> %
                                (assoc :suggestions suggestions :waiting? false)
                                select-reset))))
     (recur)))
 
 (defn- make-typeahead-state
-  [on-change]
+  [{:as args :keys [on-change rigid?]}]
   (let [c-input (chan)]
     (assoc typeahead-state-initial
-           :on-change on-change
+           :on-change  on-change
+           :rigid?     rigid?
+           :c-input    c-input
+           :c-search   (debounce c-input 250) ;; FIXME hard-coded
            :c-keypress (chan)
-           :c-input c-input
-           :c-search (debounce c-input 250) ;; FIXME hard-coded
-           :c-sugg (chan))))
+           :c-sugg     (chan))))
 
 (def ^:private keys-by-code
   {40 :down

                  :on-key-down #(on-key-down state-atom %)}]
          (if (or (not-empty suggestions) waiting?)
            [v-box
             :class "rc-typeahead-suggestions"
             :children [(when waiting?
                          [box :align :center :child [throbber :size :small :class "rc-typeahead-throbber"]])
                        (for [[ i s ] (map vector (range) suggestions)


(defn- select-prev
  [{:as state :keys [suggestions]}]
  (cond-> state
    (not-empty suggestions)
    (update :selected-index #(-> % (or -1) inc (wrap (count suggestions))))))

(defn- select-next
  [{:as state :keys [suggestions]}]
  (cond-> state
    (not-empty suggestions)
    (update :selected-index #(-> % (or -1) inc (wrap (count suggestions))))))

(defn- select-set
  [state i]
  (assoc state :selected-index i))

(defn- choice-made
  [{:as state :keys [on-change]} choice]
  (when on-change (on-change choice))
  (-> state
      (assoc :model choice :input-text "")
      (dissoc :suggestions)))

(defn- select-choose
  [{:as state :keys [suggestions selected-index on-change rigid? input-text]}]
  (cond

    (and (not rigid?) (not selected-index))
    (choice-made state input-text)

    selected-index
    (let [[search suggestion :as selected] (nth suggestions selected-index)]
      (choice-made state suggestion))

    true state))

(defn- select-reset
  [state]
