DEV: fully rely on resize observer for resizing (#17685)
Not only is the current code not needed but it's also creating invalid values on safari if the header goes out of viewport with negative values. This commit also adds a missing test for `--header-offset` property.
This commit is contained in:
parent
fd6fabc83c
commit
9a55c9c433
|
@ -183,19 +183,6 @@ const SiteHeaderComponent = MountWidget.extend(
|
|||
this.docAt = header.offsetTop;
|
||||
}
|
||||
|
||||
const headerRect = header.getBoundingClientRect();
|
||||
let headerOffsetCalc = headerRect.top + headerRect.height;
|
||||
|
||||
if (window.scrollY < 0) {
|
||||
headerOffsetCalc += window.scrollY;
|
||||
}
|
||||
|
||||
const newValue = `${headerOffsetCalc}px`;
|
||||
if (newValue !== this.currentHeaderOffsetValue) {
|
||||
this.currentHeaderOffsetValue = newValue;
|
||||
document.documentElement.style.setProperty("--header-offset", newValue);
|
||||
}
|
||||
|
||||
const main = document.querySelector("#main");
|
||||
const offsetTop = main ? main.offsetTop : 0;
|
||||
const offset = window.pageYOffset - offsetTop;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { click, render } from "@ember/test-helpers";
|
||||
import { click, render, waitUntil } from "@ember/test-helpers";
|
||||
import { count, exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
|
@ -83,4 +83,22 @@ module("Integration | Component | site-header", function (hooks) {
|
|||
await click("header.d-header");
|
||||
assert.ok(!exists(".user-menu.revamped"));
|
||||
});
|
||||
|
||||
test("header's height is setting css property", async function (assert) {
|
||||
await render(hbs`<SiteHeader />`);
|
||||
|
||||
function getProperty() {
|
||||
return getComputedStyle(document.body).getPropertyValue(
|
||||
"--header-offset"
|
||||
);
|
||||
}
|
||||
|
||||
document.querySelector(".d-header").style.height = 90 + "px";
|
||||
await waitUntil(() => getProperty() === "90px", { timeout: 100 });
|
||||
assert.strictEqual(getProperty(), "90px");
|
||||
|
||||
document.querySelector(".d-header").style.height = 60 + "px";
|
||||
await waitUntil(() => getProperty() === "60px", { timeout: 100 });
|
||||
assert.strictEqual(getProperty(), "60px");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue