Merge pull request #106 from status-im/bug/close-dropdown

[bug] close dropdown when clicking outside of it
This commit is contained in:
Teemu Patja 2017-10-30 21:29:31 +02:00 committed by GitHub
commit 4060bf0f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -36,12 +36,12 @@
(def user-dropdown-open? (r/atom false)) (def user-dropdown-open? (r/atom false))
(defn user-dropdown [user items] (defn user-dropdown [user items]
(let [menu (if @user-dropdown-open? (let [menu (if @(rf/subscribe [:user-dropdown-open?])
[:div.ui.menu.transition.visible] [:div.ui.menu.transition.visible]
[:div.ui.menu.transition.hidden]) [:div.ui.menu.transition.hidden])
avatar-url (:avatar_url user)] avatar-url (:avatar_url user)]
[:div.ui.left.item.dropdown [:div.ui.left.item.dropdown
{:on-click #(swap! user-dropdown-open? not)} {:on-click #(rf/dispatch [:user-dropdown-open])}
[:div.item [:div.item
[:img.ui.mini.circular.image {:src avatar-url}]] [:img.ui.mini.circular.image {:src avatar-url}]]
[:div.item [:div.item

View File

@ -430,3 +430,18 @@
:metrics-loaded :metrics-loaded
(fn [db [_]] (fn [db [_]]
(dissoc db :metrics-loading?))) (dissoc db :metrics-loading?)))
(defn close-dropdown []
(dispatch [:user-dropdown-close]))
(reg-event-db
:user-dropdown-open
(fn [db [_]]
(.addEventListener js/window "click" close-dropdown)
(assoc db :user-dropdown-open? true)))
(reg-event-db
:user-dropdown-close
(fn [db [_]]
(.removeEventListener js/window "click" close-dropdown)
(assoc db :user-dropdown-open? false)))

View File

@ -75,3 +75,8 @@
:metrics-loading? :metrics-loading?
(fn [db _] (fn [db _]
(:metrics-loading? db))) (:metrics-loading? db)))
(reg-sub
:user-dropdown-open?
(fn [db _]
(:user-dropdown-open? db)))