Merge pull request #106 from status-im/bug/close-dropdown
[bug] close dropdown when clicking outside of it
This commit is contained in:
commit
4060bf0f67
|
@ -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
|
||||||
|
|
|
@ -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)))
|
||||||
|
|
|
@ -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)))
|
||||||
|
|
Loading…
Reference in New Issue