From 6fe6886c191d0588eac6af851e1c691b995d4209 Mon Sep 17 00:00:00 2001 From: Gheorghe Pinzaru Date: Wed, 17 Jun 2020 15:05:07 +0300 Subject: [PATCH] Fix missing ref on search input Fixes #10833 Cleanup search on blur if no chat found Signed-off-by: Gheorghe Pinzaru --- src/status_im/ui/components/search_input/view.cljs | 11 +++++++---- src/status_im/ui/screens/home/views.cljs | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/status_im/ui/components/search_input/view.cljs b/src/status_im/ui/components/search_input/view.cljs index ef444c762406..dcbaeb63cdbb 100644 --- a/src/status_im/ui/components/search_input/view.cljs +++ b/src/status_im/ui/components/search_input/view.cljs @@ -7,11 +7,11 @@ (defn search-input [{:keys [search-active?]}] (let [input-ref (atom nil) search-active? (or search-active? (reagent/atom nil))] - (fn [{:keys [on-focus on-change on-cancel search-filter auto-focus]}] + (fn [{:keys [on-focus on-change on-blur on-cancel search-filter auto-focus]}] [quo/text-input {:placeholder (i18n/label :t/search) :blur-on-submit true :multiline false - :ref #(reset! input-ref %) + :get-ref #(reset! input-ref %) :default-value search-filter :auto-focus auto-focus :on-cancel on-cancel @@ -23,13 +23,16 @@ :padding-bottom 2} :before {:icon :main-icons/search :style {:padding-horizontal 8} - :on-press #(.focus ^js @input-ref) + :on-press #(some-> ^js @input-ref (.focus)) :icon-opts {:color (:icon-02 @colors/theme)}} :on-focus #(do (when on-focus (on-focus search-filter)) (reset! search-active? true)) - :on-blur #(reset! search-active? false) + :on-blur #(do + (when on-blur + (on-blur)) + (reset! search-active? false)) :on-change (fn [e] (let [^js native-event (.-nativeEvent ^js e) text (.-text native-event)] diff --git a/src/status_im/ui/screens/home/views.cljs b/src/status_im/ui/screens/home/views.cljs index b06af69ddd1c..639e24a328b3 100644 --- a/src/status_im/ui/screens/home/views.cljs +++ b/src/status_im/ui/screens/home/views.cljs @@ -85,13 +85,15 @@ (defonce search-active? (reagent/atom false)) -(defn search-input-wrapper [search-filter] +(defn search-input-wrapper [search-filter chats] [react/view {:padding-horizontal 16 :padding-vertical 10} [search-input/search-input {:search-active? search-active? :search-filter search-filter :on-cancel #(re-frame/dispatch [:search/home-filter-changed nil]) + :on-blur #(when-not (seq chats) + (re-frame/dispatch [:search/home-filter-changed nil])) :on-focus (fn [search-filter] (when-not search-filter (re-frame/dispatch [:search/home-filter-changed ""]))) @@ -116,7 +118,7 @@ :data chats :render-fn (fn [home-item] [inner-item/home-list-item home-item]) :header (when (or (seq chats) @search-active?) - [search-input-wrapper search-filter]) + [search-input-wrapper search-filter chats]) :footer (if (and (not hide-home-tooltip?) (not @search-active?)) [home-tooltip-view] [react/view {:height 68}])}]))))