From c84bbee02ef90c3755130398b6bb9344b70dc0e7 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 23 Apr 2026 11:14:41 +0200 Subject: [PATCH] scrollbar: methodize target scroll handler and watch for target resize --- CHANGELOG.md | 5 ++- src/client/widgets/sliders/scrollbar.mjs | 50 ++++++++++++++---------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3566ac9b..cab4cbe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,10 @@ ## 1.30.3 --widgets +- bug fixes + - scrollbar: missing update upon target container resize + +- widgets - file: remember last visited directy per widget if `directory` property is not set - knob: add `horizontal` mode - eq: filter responses are now only computed when needed; the widget's value is no longer exposed / sync'ed. diff --git a/src/client/widgets/sliders/scrollbar.mjs b/src/client/widgets/sliders/scrollbar.mjs index 9c6ea2e8..9291e63d 100644 --- a/src/client/widgets/sliders/scrollbar.mjs +++ b/src/client/widgets/sliders/scrollbar.mjs @@ -147,34 +147,42 @@ export default class Scrollbar extends StaticProperties(Fader, { this.unbindTarget() } }, {context: this}) - var onScroll = (e, init)=>{ - - if (!this.scrollTarget || e.locked) return - - var index = this.getProp('horizontal') ? 0 : 1, - size = this.getProp('horizontal') ? this.width : this.height - - this.thumbSize = this.scrollTarget.scrollThumb[index] - this.cssVars.knobSize = Math.max(this.thumbSize * size, 30) - - if (init && this.value) { - // panel (re)createed: restore scroll state - this.setValue(this.value, {fromScrollEvent: false, send: false, sync: false}) - } else if (this.scrollTarget.scroll[index] != this.value) { - // panel scrolling: update scroll state - this.setValue(this.scrollTarget.scroll[index], {fromScrollEvent: true, send: !init, sync: !init}) - } - - } fastdom.measure(()=>{ if (!this.scrollTarget) return - this.scrollTarget.on('scroll', onScroll) - onScroll({}, true) + this.scrollTarget.on('scroll', this.targetScroll.bind(this)) + this.scrollTarget.on('resize', ()=>{ + if (this.scrollTarget) { + this.scrollTarget.trigger('scroll', {}) + this.targetScroll({}, true) + } + }, {element: this.scrollTarget.widget}) + this.targetScroll({}, true) }) } + targetScroll(e, init) { + + if (!this.scrollTarget || (e && e.locked)) return + + var index = this.getProp('horizontal') ? 0 : 1, + size = this.getProp('horizontal') ? this.width : this.height + + this.thumbSize = this.scrollTarget.scrollThumb[index] + this.cssVars.knobSize = Math.max(this.thumbSize * size, 30) + + if (init && this.value) { + // panel (re)createed: restore scroll state + this.setValue(this.value, {fromScrollEvent: false, send: false, sync: false}) + } else if (this.scrollTarget.scroll[index] != this.value) { + // panel scrolling: update scroll state + this.setValue(this.scrollTarget.scroll[index], {fromScrollEvent: true, send: !init, sync: !init}) + } + + } + + setValue(v, options={}) { super.setValue(v, options)