Giter VIP home page Giter VIP logo

Comments (29)

sccolbert avatar sccolbert commented on August 23, 2024

Our implementation is closer in behavior to this:
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded

Which is not widely supported by browsers.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

If you can get scrollIntoView to behave like our scrollIfNeeded across browsers, I'm happy to ditch our version.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

and scrollIfNeeded does take a threshold option, so I'm not sure I follow you on that part.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

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.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

I still don't follow. The third argument to scrollIfNeeded is an optional threshold. What are you asking for here?

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

Our implementation is closer in behavior to this:
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded

Ah, then our implementation is buggy, in that it doesn't take into account the element width.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

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

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

I still don't follow. The third argument to scrollIfNeeded is an optional threshold. What are you asking for here?

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.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

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.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

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

Even vertically, it has problems and is scrolling unnecessarily. For example, see jupyterlab/jupyterlab#478.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

PEBKAC - you're calling scrollIfNeeded on the wrong node.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

It was easy enough to add a threshold, which I knew would be a command request, so there it is.

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

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

You are asking it to scroll the large container node into view, instead of the element with focus. Call scrollIfNeeded on the input node, and I'll bet you'll see better behavior.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

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.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

Yeah, I realized that as soon as I typed my response.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

The algorithm for scrollIntoView correctly handles this case where the element is larger than the viewport.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

Yeah, I realized that as soon as I typed my response.

:)

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

I'm happy to submit a PR, though.

from phosphor.

afshin avatar afshin commented on August 23, 2024

n.b., Here's a bit of background history.

scrollIfNeeded is used in a few spots in JupyterLab (and thus implemented multiple times). We added it into phosphor so we wouldn't have to keep repeating ourselves when we switch over to mono-repo. The threshold argument doesn't exist in the JupyterLab versions, but since we were making it available to all future phosphor users, we decided it would be good to add that argument even though it's not being used.

For example, if you consider the notebook/widget version:

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.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

you'll see that threshold was hard-coded

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?

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

I'm working on a PR.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

cf #126

from phosphor.

afshin avatar afshin commented on August 23, 2024

I don't remember what the original reason for the threshold was, I'm afraid.

The native scrollIntoView might actually be sufficient.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

The problem with the native scrollIntoView is that several browsers don't support the options argument, which is what we need to get the "if needed" part of the behavior.

from phosphor.

afshin avatar afshin commented on August 23, 2024

Oh right, good call, that was the catch.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

Yeah, agreed that if we need the IfNeeded part, we'll have to implement our own.

from phosphor.

jasongrout avatar jasongrout commented on August 23, 2024

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

from phosphor.

afshin avatar afshin commented on August 23, 2024

I assume that's exactly the sort of reasoning that went into it, but I can't say so authoritatively.

from phosphor.

sccolbert avatar sccolbert commented on August 23, 2024

fixed

from phosphor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.