Skip to content

feat(common): add getOffset method to ViewportScroller #70469

Description

@AyushDubey23

Which @angular/* package(s) are relevant/related to the feature request?

common

Description

ViewportScroller provides setOffset(offset) to configure scroll offsets (commonly used for sticky headers or floating toolbars) via a static coordinate tuple [x, y] or a dynamic callback () => [x, y].

However, ViewportScroller currently does not provide a getter to retrieve the configured offset. Code that works with the scroller may need to inspect or reuse the effective offset without maintaining duplicate state or re-measuring the element that provides the offset.

Proposed solution

Add getOffset(): [number, number] to ViewportScroller:

  • On ViewportScroller: Declare abstract getOffset(): [number, number];
  • On BrowserViewportScroller: Implement getOffset(): [number, number] returning this.offset()
  • On NullViewportScroller: Implement getOffset(): [number, number] returning [0, 0]

Alternatives considered

Maintaining separate application-level state or services to track header height/offset calculations outside of ViewportScroller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commonIssues related to APIs in the @angular/common packagegemini-triagedLabel noting that an issue has been triaged by gemini

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions