scrollbar: methodize target scroll handler and watch for target resize

This commit is contained in:
jean-emmanuel 2026-04-23 11:14:41 +02:00
parent 7fc5372ca1
commit c84bbee02e
2 changed files with 33 additions and 22 deletions

View file

@ -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.

View file

@ -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)