From 84d379b08264b9c663e36ce7e33ae61d92d6b824 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 25 Jun 2024 15:38:17 +0200 Subject: [PATCH] Do not trigger ScrollButton event unless clicked (#6938) --- panel/layout/feed.py | 2 +- panel/models/column.ts | 19 ++++++++++++++++--- panel/models/feed.ts | 22 +--------------------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/panel/layout/feed.py b/panel/layout/feed.py index 58144e2fdc..fc711ee4f2 100644 --- a/panel/layout/feed.py +++ b/panel/layout/feed.py @@ -195,7 +195,7 @@ def _process_event(self, event: ScrollButtonClick) -> None: n_visible = self.visible_range[-1] - self.visible_range[0] with edit_readonly(self): # plus one to center on the last object - self.visible_range = (max(n - n_visible + 1, 0), n) + self.visible_range = (min(max(n - n_visible + 1, 0), n), n) with param.discard_events(self): # reset the buffers and loaded objects diff --git a/panel/models/column.ts b/panel/models/column.ts index 5dbca25a72..a050e67c69 100644 --- a/panel/models/column.ts +++ b/panel/models/column.ts @@ -1,6 +1,14 @@ -import {Column as BkColumn, ColumnView as BkColumnView} from "@bokehjs/models/layouts/column" -import * as DOM from "@bokehjs/core/dom" +import {ModelEvent} from "@bokehjs/core/bokeh_events" +import {div} from "@bokehjs/core/dom" import type * as p from "@bokehjs/core/properties" +import type {EventCallback} from "@bokehjs/model" +import {Column as BkColumn, ColumnView as BkColumnView} from "@bokehjs/models/layouts/column" + +export class ScrollButtonClick extends ModelEvent { + static { + this.prototype.event_name = "scroll_button_click" + } +} export class ColumnView extends BkColumnView { declare model: Column @@ -62,7 +70,7 @@ export class ColumnView extends BkColumnView { override render(): void { super.render() - this.scroll_down_button_el = DOM.createElement("div", {class: "scroll-button"}) + this.scroll_down_button_el = div({class: "scroll-button"}) this.shadow_el.appendChild(this.scroll_down_button_el) this.el.addEventListener("scroll", () => { this.record_scroll_position() @@ -70,6 +78,7 @@ export class ColumnView extends BkColumnView { }) this.scroll_down_button_el.addEventListener("click", () => { this.scroll_to_latest() + this.model.trigger_event(new ScrollButtonClick()) }) } @@ -118,4 +127,8 @@ export class Column extends BkColumn { view_latest: [Bool, false], })) } + + on_click(callback: EventCallback): void { + this.on_event(ScrollButtonClick, callback) + } } diff --git a/panel/models/feed.ts b/panel/models/feed.ts index 6a4521fdea..c2231724f3 100644 --- a/panel/models/feed.ts +++ b/panel/models/feed.ts @@ -2,14 +2,6 @@ import {Column, ColumnView} from "./column" import type * as p from "@bokehjs/core/properties" import {build_views} from "@bokehjs/core/build_views" import type {UIElementView} from "@bokehjs/models/ui/ui_element" -import {ModelEvent} from "@bokehjs/core/bokeh_events" -import type {EventCallback} from "@bokehjs/model" - -export class ScrollButtonClick extends ModelEvent { - static { - this.prototype.event_name = "scroll_button_click" - } -} export class FeedView extends ColumnView { declare model: Feed @@ -89,21 +81,13 @@ export class FeedView extends ColumnView { return created } - override scroll_to_latest(emit_event: boolean = true): void { - if (emit_event) { - this.model.trigger_event(new ScrollButtonClick()) - } - super.scroll_to_latest() - } - override trigger_auto_scroll(): void { const limit = this.model.auto_scroll_limit const within_limit = this.distance_from_latest <= limit if (limit == 0 || !within_limit) { return } - - this.scroll_to_latest(false) + this.scroll_to_latest() } } @@ -132,8 +116,4 @@ export class Feed extends Column { visible_children: [List(Str), []], })) } - - on_click(callback: EventCallback): void { - this.on_event(ScrollButtonClick, callback) - } }