Refactor autoscrolling code

This commit is contained in:
Saskia Lindner 2017-08-28 17:18:28 +02:00
parent d5aefa9b1d
commit 6276a76cbb
3 changed files with 5 additions and 6 deletions

View File

@ -227,7 +227,7 @@
(:filter-type item) ": " [:span.filter-item-string (:query item)]
[:span.icon-button [components/icon-remove]]]])
@filter-items)]]
[components/autoscroll-list {:class "panel-content-scrollable" :scroll? true}
[components/autoscroll-list {:class "panel-content-scrollable"}
[:table
{:style {:margin-bottom 10}
:cell-spacing "0" :width "100%"}

View File

@ -23,7 +23,7 @@
;; at-end?: element.scrollHeight - element.scrollTop === element.clientHeight
(> tolerance (- (.-scrollHeight el) (.-scrollTop el) (.-clientHeight el))))
(defn autoscroll-list [{:keys [class scroll?] :as opts} childr]
(defn autoscroll-list [{:keys [class]} child]
(let [should-scroll (r/atom true)]
(r/create-class
{:display-name "autoscroll-list"
@ -37,9 +37,8 @@
(reset! should-scroll (scrolled-to-end? n 100))))
:component-did-update
(fn [this]
(let [scroll? (:scroll? (r/props this))
n (r/dom-node this)]
(when (and scroll? @should-scroll)
(let [n (r/dom-node this)]
(when @should-scroll
(scroll! n [0 (.-scrollTop n)] [0 (.-scrollHeight n)] 1600))))
:reagent-render
(fn [{:keys [class]} child]

View File

@ -95,7 +95,7 @@
flex: 1;
}
#--re-frame-trace-- .panel-content-scrollable {
margin: 10px;
margin: 0 0 10px 5px;
overflow: auto;
flex: 1 1 auto;
}