-
Notifications
You must be signed in to change notification settings - Fork 168
Scroll if needed #125
Comments
Our implementation is closer in behavior to this: Which is not widely supported by browsers. |
If you can get |
and |
If you want, we can implement the algorithm with a threshold, if it's needed. I only see one place where it is used, and that doesn't use the threshold. |
I still don't follow. The third argument to |
Ah, then our implementation is buggy, in that it doesn't take into account the element width. |
Bug is a strong word :) It's working as designed, but is only designed to scroll vertically: https://github.com/phosphorjs/phosphor/blob/master/src/dom/query.ts#L92-L95 |
I'm saying we could implement the algorithm in scrollIntoView, but with a threshold. Separately, I'm questioning the need for a threshold parameter, since it doesn't seem to be used, at least in this repo. |
There's lots of functionality in this repo which is not used by the repo itself :) It was easy enough to add a threshold, which I knew would be a common request, so there it is. |
Even vertically, it has problems and is scrolling unnecessarily. For example, see jupyterlab/jupyterlab#478. |
PEBKAC - you're calling |
Easy enough, I know. I don't have your foresight that it will be requested, though, and saw it as a premature customization. Hence my questioning it... |
You are asking it to scroll the large container node into view, instead of the element with focus. Call |
The point is that if you are asking a node that is larger than the viewport to scroll into view, and it's already in view, scrollIfNeeded, as implemented, will unnecessarily scroll so the bottom is aligned with the bottom. Edit: that is, if the top is in view, but the bottom is below the viewport. |
Yeah, I realized that as soon as I typed my response. |
The algorithm for scrollIntoView correctly handles this case where the element is larger than the viewport. |
:) |
I'm happy to submit a PR, though. |
n.b., Here's a bit of background history.
For example, if you consider the https://github.com/jupyter/jupyterlab/blob/master/src/notebook/notebook/widget.ts#L998-L1006 ... you'll see that threshold was hard-coded. We decided to make that an argument instead in the phosphor version. |
Dummy me wasn't seeing it in the code I was originally looking at - thanks for pointing out at least one place it was being used. I'm still not sure it's a good idea to have the threshold. What was the problem without the threshold, and is it fixed if we implement a proper scrollIfNeeded? |
I'm working on a PR. |
cf #126 |
I don't remember what the original reason for the threshold was, I'm afraid. The native |
The problem with the native |
Oh right, good call, that was the catch. |
Yeah, agreed that if we need the |
Perhaps the threshold accounted for padding/border in the elements? In other words, if my element is padded by 10 pixels, then I'm okay with it being actually 10 pixels off screen... |
I assume that's exactly the sort of reasoning that went into it, but I can't say so authoritatively. |
fixed |
Why do we implement our own scrollIfNeeded (https://github.com/phosphorjs/phosphor/blob/master/src/dom/query.ts#L89) instead of using the browser's scrollIntoView (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)?
Alternatively, I think the scrollIfNeeded algorithm could be improved by following (maybe with a threshold?) the spec for scrollIntoView: https://drafts.csswg.org/cssom-view/#element-scrolling-members
The text was updated successfully, but these errors were encountered: