Skip to content

feat: add reposition and close scroll strategy (#DS-1920) - #1781

Open
NikGurev wants to merge 10 commits into
mainfrom
feat/DS-1920
Open

feat: add reposition and close scroll strategy (#DS-1920)#1781
NikGurev wants to merge 10 commits into
mainfrom
feat/DS-1920

Conversation

@NikGurev

Copy link
Copy Markdown
Contributor

Summary

Implemented separate scroll strategy that enhances Angular CDK scroll strategies.

  • Behavior is simple: hide if originElement is outside of view (cdkScrollable) and reposition otherwise.

  • It gets origin element from FlexibleConnectedPositionStrategy for built-in components using Angular Overlay, but gives the ability to provide in runtime for custom resolution.

@NikGurev NikGurev self-assigned this Jul 24, 2026
@NikGurev
NikGurev requested a review from lskramarov as a code owner July 24, 2026 15:50
@NikGurev NikGurev added the enhancement New feature or request label Jul 24, 2026
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit a340a7e):

https://koobiq-next--prs-1781-ai6sk6pf.web.app

(expires Thu, 30 Jul 2026 12:11:47 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: c9e37e518febda70d0317d07e8ceb35ac43c534c

@NikGurev
NikGurev requested a review from artembelik July 24, 2026 15:59
@NikGurev
NikGurev marked this pull request as draft July 27, 2026 07:10
@NikGurev
NikGurev marked this pull request as ready for review July 27, 2026 12:36
@artembelik
artembelik requested a review from Copilot July 27, 2026 12:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new CDK-overlay scroll strategy in @koobiq/components/core that repositions overlays on scroll and emits a “hide” signal when the trigger/overlay goes out of bounds, making it usable both for built-in overlay-based components and custom overlay integrations.

Changes:

  • Added KbqHideOnScrollStrategy, config, hooks, and kbqHideOnScrollStrategyFactory as public core API.
  • Exported the new strategy from packages/components/core/public-api.ts.
  • Added Jest unit tests covering lifecycle, origin derivation, and out-of-bounds behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tools/public_api_guard/components/core.api.md Adds the new scroll strategy types/functions to the public API snapshot.
packages/components/core/public-api.ts Exports the new hide-on-scroll strategy from core’s public entrypoint.
packages/components/core/overlay/hide-on-scroll.strategy.ts Implements the new scroll strategy, config, hooks, and factory.
packages/components/core/overlay/hide-on-scroll.strategy.spec.ts Adds unit tests for the strategy’s lifecycle and boundary detection behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +70 to +72
enable(): void {
if (this.scrollSubscription) return;

Comment on lines +84 to +97
.subscribe(() => {
this.overlayRef!.updatePosition();

const isOutside = this.originElement
? this._isOriginOutsideAncestors(this.originElement)
: this._isOverlayOutsideViewport();

if (isOutside) {
this.ngZone.run(() => {
this.hideSubject.next();
this.hooks?.onHide?.();
});
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

предлагаю не вводить новые суффиксы для имен файлов - hide-on-scroll-strategy.ts

https://angular.dev/style-guide#match-file-names-to-the-typescript-identifier-within

if (!this.originElement) {
// FlexibleConnectedPositionStrategy stores the origin as a private field.
// Reading it here avoids requiring callers to pass originElement explicitly.
this.originElement = this.coerceOriginElement((overlayRef.getConfig().positionStrategy as any)?._origin);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

без anyне обойтись?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это приватное поле, так что да

);
}

private _isOverlayOutsideViewport(): boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у cdk есть метод, мб то что тебе нужно - isElementScrolledOutsideView

* Pass `onHide` via the factory returned by `kbqHideOnScrollStrategyFactory` so the strategy
* calls it when the trigger scrolls out of bounds.
*/
export class KbqHideOnScrollStrategy implements ScrollStrategy {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

текущее имя вводит в заблуждение, можно подумать, что стратегия скрывает оверлей при любом скролле, по сути это RepositionScrollStrategy + доп проверка на выход за границу видимости

может стоит отнаследовать RepositionScrollStrategy и сделать оверрайд метода закрытия?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

изучу вопрос

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants