From bebf7091ecaac8837812e89e8f8a12231a0a1e62 Mon Sep 17 00:00:00 2001 From: Gregg8 Date: Mon, 28 Nov 2016 12:15:31 +1100 Subject: [PATCH] Fixes #113 When :no-clip? is true, popover repositioning is not perfect --- src/re_com/popover.cljs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/re_com/popover.cljs b/src/re_com/popover.cljs index 1928fc16..69ae7ce8 100644 --- a/src/re_com/popover.cljs +++ b/src/re_com/popover.cljs @@ -350,19 +350,26 @@ :as args}] {:pre [(validate-args-macro popover-content-wrapper-args-desc args "popover-content-wrapper")]} ;(assert ((complement nil?) showing-injected?) "Must specify a showing-injected? atom") - (let [left-offset (reagent/atom 0) - top-offset (reagent/atom 0)] + (let [left-offset (reagent/atom 0) + top-offset (reagent/atom 0) + position-no-clip-popover (fn position-no-clip-popover + [this] + (when no-clip? + (let [node (reagent/dom-node this) + popover-point-node (.-parentNode node) ;; Get reference to rc-popover-point node + bounding-rect (.getBoundingClientRect popover-point-node)] ;; The modern magical way of getting offsetLeft and offsetTop. Returns this: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMClientRect + (reset! left-offset (.-left bounding-rect)) + (reset! top-offset (.-top bounding-rect)))))] (reagent/create-class {:display-name "popover-content-wrapper" :component-did-mount (fn [this] - (when no-clip? - (let [node (reagent/dom-node this) - popover-point-node (.-parentNode node) ;; Get reference to rc-popover-point node - bounding-rect (.getBoundingClientRect popover-point-node)] ;; The modern magical way of getting offsetLeft and offsetTop. Returns this: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMClientRect - (reset! left-offset (.-left bounding-rect)) - (reset! top-offset (.-top bounding-rect))))) + (position-no-clip-popover this)) + + :component-did-update + (fn [this] + (position-no-clip-popover this)) :reagent-render (fn