Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #8513 - Sticky progress bar doesn't hide (at least safari/chrom… #8556

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7731,10 +7731,20 @@ export class SurveyModel extends SurveyElementCore
disposeCallback: () => void;

private onScrollCallback: () => void;
// private _lastScrollTop = 0;
public _isElementShouldBeSticky(selector: string): boolean {
if (!selector) return false;
const topStickyContainer = this.rootElement.querySelector(selector);
if (!!topStickyContainer) {
// const scrollDirection = this.rootElement.scrollTop > this._lastScrollTop ? "down" : "up";
// this._lastScrollTop = this.rootElement.scrollTop;
return this.rootElement.scrollTop > 0 && topStickyContainer.getBoundingClientRect().y <= this.rootElement.getBoundingClientRect().y;
}
return false;
}
public onScroll(): void {
if (!!this.rootElement) {
const topStickyContainer = this.rootElement.querySelector(".sv-components-container-center");
if (!!topStickyContainer && topStickyContainer.getBoundingClientRect().y <= this.rootElement.getBoundingClientRect().y) {
if (this._isElementShouldBeSticky(".sv-components-container-center")) {
this.rootElement.classList && this.rootElement.classList.add("sv-root--sticky-top");
} else {
this.rootElement.classList && this.rootElement.classList.remove("sv-root--sticky-top");
Expand Down
21 changes: 21 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20169,7 +20169,28 @@ QUnit.test("Delete panel with questions", (assert) => {
assert.notOk(survey.getPanelByName("panel1"), "#5");
assert.notOk(survey.getQuestionByName("question1"), "#6");
});
QUnit.test("_isElementShouldBeSticky", (assert) => {
const survey = new SurveyModel({});
const topStickyContainer: any = {
getBoundingClientRect: () => ({ y: 64 })
};
const rootElement: any = {
getBoundingClientRect: () => ({ y: 64 }),
querySelector: () => topStickyContainer,
scrollTop: 0
};
survey.rootElement = rootElement;

assert.notOk(survey._isElementShouldBeSticky(".test"), "no scrolling");

rootElement.scrollTop = 50;
assert.ok(survey._isElementShouldBeSticky(".test"), "content is scrolled");

assert.notOk(survey._isElementShouldBeSticky(""), "empty selector - always false (with scroll)");

rootElement.scrollTop = 0;
assert.notOk(survey._isElementShouldBeSticky(""), "empty selector - always false (no scroll)");
});
QUnit.test("survey navigateToUrl encode url", function (assert) {
var survey = new SurveyModel({
questions: [
Expand Down