GithubHelp home page GithubHelp logo

Comments (4)

atscott avatar atscott commented on May 3, 2024

This looks more like a BrowserViewportScroller issue rather than a Router one. scrollToElement relies only on the internal offset and does not look at the styles on the element. There's no runnable reproduction in this report but I suspect if you provided a custom implementation that does that instead of what's here, it would work correctly.

from angular.

mmorris8 avatar mmorris8 commented on May 3, 2024

That would be the function that needs to change for this bug to be fixed.

And I call it out as a bug because intuitively the behavior of this scrollTo should match the native behavior of hashes. The scrollMargin css property exists precisely because of the sticky and fixed headers. The offset property can remain for backwards compatibility, but the properties need to be honored because that's why they exist. They are honored by all browsers except IE.

The below should work. I'll look into figuring out how to do a pull request over the weekend.

private scrollToElement(el: HTMLElement): void {
    const rect = el.getBoundingClientRect();
    const left = rect.left + this.window.pageXOffset;
    const top = rect.top + this.window.pageYOffset;
    const marginLeft = parseFloat(getComputedStyle(el).scrollMarginLeft);
    const marginTop = parseFloat(getComputedStyle(el).scrollMarginTop);

    const offset = this.offset();
    this.window.scrollTo(left + marginLeft - offset[0], top + marginTop - offset[1]);
  }

from angular.

atscott avatar atscott commented on May 3, 2024

Right, I agree.

They are honored by all browsers except IE

This, historically, would be the reason the issue exists. The implementation here has existed since before IE was dropped and potentially before the current set of browsers all fully supported it as well.

from angular.

michael-lloyd-morris avatar michael-lloyd-morris commented on May 3, 2024

This is the account that I will be issuing the PR from. I'll look up the guidelines and try to get something in on Saturday. I imagine test revision will be the largest segment.

from angular.

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.