Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/components/scrollbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,22 @@ export default function ScrollBar(options) {

if (height < 0) height = 0;
if (width < 0) width = 0;
if (render && height && width) setValue(scroll);
if (render && trackLength()) setValue(scroll);
}

/**
* Length the thumb travels along the scrollbar's axis. The cross axis is
* always 0 (the bar is thinner than the thumb), so only this one counts.
*/
function trackLength() {
return isVertical ? height : width;
}

function setValue(val) {
if (!height || !width) resize(false);
// Measure each time, as the parent can change size without a window
// resize (e.g. the sidebar opening). A detached bar has an empty rect;
// show() measures it once it's back on the page.
if ($scrollbar.isConnected) resize(false);

//Make sure value is between 0 and 1
if (val < 0) val = 0;
Expand Down Expand Up @@ -230,6 +241,9 @@ export default function ScrollBar(options) {
$scrollbar.classList.remove("hide");
if (!$scrollbar.isConnected) {
options.parent.append($scrollbar);
// The value may have been set while detached, against an empty
// rect; measure again so the thumb isn't painted at 0.
resize();
if (typeof onshow === "function") onshow();
}
}
Expand Down
Loading