Skip to content

Commit 24e7f70

Browse files
authored
fix(scrim): update loader scale on resize of component. (#7419)
**Related Issue:** #7420 ## Summary - Correctly starts observing the resize observer - Adds tests
1 parent c1af3c7 commit 24e7f70

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

packages/calcite-components/src/components/scrim/scrim.e2e.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ describe("calcite-scrim", () => {
110110
});
111111

112112
describe("Responsive loading spinner", () => {
113-
const testValues: { width: number; height: number; scale: Scale }[] = [
113+
type ScaleSize = { width: number; height: number; scale: Scale };
114+
const testValues: ScaleSize[] = [
114115
{
115116
width: BREAKPOINTS.s - 1,
116117
height: 800,
@@ -166,6 +167,45 @@ describe("calcite-scrim", () => {
166167
expect(await loader.getProperty("scale")).toBe(scaleSize.scale);
167168
});
168169
});
170+
171+
it("should responsively scale loading spinner on resize", async () => {
172+
const page = await newE2EPage();
173+
await page.setContent(html`<style>
174+
.scrim-container {
175+
display: flex;
176+
flex: 1;
177+
position: relative;
178+
overflow: auto;
179+
}
180+
</style>
181+
<div class="scrim-container">
182+
<calcite-scrim loading><p>I'm a panel that is loading.</p></calcite-scrim>
183+
</div>`);
184+
await page.waitForChanges();
185+
186+
for (let i = 0; i < testValues.length; i++) {
187+
const { width, height, scale } = testValues[i];
188+
const scrimContainer = await page.find(".scrim-container");
189+
expect(scrimContainer).toBeDefined();
190+
await page.$eval(
191+
".scrim-container",
192+
(scrimContainer: HTMLElement, width: number, height: number) => {
193+
scrimContainer.style.width = `${width}px`;
194+
scrimContainer.style.height = `${height}px`;
195+
},
196+
width,
197+
height
198+
);
199+
await page.waitForChanges();
200+
const style = await scrimContainer.getComputedStyle();
201+
expect(style.width).toBe(`${width}px`);
202+
expect(style.height).toBe(`${height}px`);
203+
const loader = await page.find("calcite-scrim >>> calcite-loader");
204+
expect(loader).toBeDefined();
205+
expect(await loader.isVisible()).toBe(true);
206+
expect(await loader.getProperty("scale")).toBe(scale);
207+
}
208+
});
169209
});
170210

171211
describe("CSS properties for light/dark modes", () => {

packages/calcite-components/src/components/scrim/scrim.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class Scrim implements LocalizedComponent, T9nComponent {
8484
connectedCallback(): void {
8585
connectLocalized(this);
8686
connectMessages(this);
87+
this.resizeObserver?.observe(this.el);
8788
}
8889

8990
async componentWillLoad(): Promise<void> {
@@ -93,6 +94,7 @@ export class Scrim implements LocalizedComponent, T9nComponent {
9394
disconnectedCallback(): void {
9495
disconnectLocalized(this);
9596
disconnectMessages(this);
97+
this.resizeObserver?.disconnect();
9698
}
9799

98100
// --------------------------------------------------------------------------

packages/calcite-components/src/demos/scrim.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ <h1 style="margin: 0 auto; text-align: center">Scrim</h1>
3939
<div class="parent">
4040
<div class="child">
4141
Default
42-
<div tabindex="0" style="position: relative; width: 400px; height: 400px; padding: 25px">
42+
<div
43+
tabindex="0"
44+
style="position: relative; width: 400px; height: 400px; padding: 25px; resize: both; overflow: auto"
45+
>
4346
<calcite-scrim></calcite-scrim>
44-
<div style="width: 400px; height: 400px; overflow: auto">
47+
<div style="width: 100%; height: 100%; overflow: auto">
4548
<p>
4649
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum
4750
tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas
@@ -72,9 +75,12 @@ <h1 style="margin: 0 auto; text-align: center">Scrim</h1>
7275
<!-- loading scrim panel -->
7376
<div class="child">
7477
Loading
75-
<div tabindex="0" style="position: relative; width: 400px; height: 400px; padding: 25px">
78+
<div
79+
tabindex="0"
80+
style="position: relative; width: 400px; height: 400px; padding: 25px; resize: both; overflow: auto"
81+
>
7682
<calcite-scrim loading></calcite-scrim>
77-
<div style="width: 400px; height: 400px; overflow: auto">
83+
<div style="width: 100%; height: 100%; overflow: auto">
7884
<p>
7985
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum
8086
tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas

0 commit comments

Comments
 (0)