             (lookup-suggestions on-change-ch text)))]
 
     (debounced-callback state suggest-fn on-change-ch 100)
-
+    (.addEventListener (aget js/document "body" ) "click" #(when (:current-text @state) (close)))
     (r/create-class
      {:reagent-render
       (fn [{:keys [value on-change value-fn label-fn match-fn suggest-fn placeholder]}]

          timer (timeout ms)
          [new-val ch] (alts! [in timer])]
      (condp = ch
        timer (do (swap! state assoc :suggestions (<! (suggest-fn val)))
                  (recur nil))
        in (when new-val (recur new-val))))))


           [:input {:type "text"
                    :on-change handle-input-change
                    :on-focus #(swap! state assoc :focused true)
                    :value (or (:current-text @state)
                               (match-fn value))}]

           (when (and (:focused @state) (not (empty? (:suggestions @state))))
             [:div.suggestions
              (for [i (:suggestions @state)] ^{:key (pr-str (value-fn i))}
                [:div.option {:on-click #(do (when on-change (on-change (value-fn i)))
                                             (close))}
                 (label-fn i)])])]))})))
