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

fix(dialog): no longer apply transform styling unless dragEnabled or resizable #10503

Merged
merged 5 commits into from
Oct 8, 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
17 changes: 14 additions & 3 deletions packages/calcite-components/src/components/dialog/dialog.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,17 @@ describe("calcite-dialog", () => {
expect(await alert.getProperty("embedded")).toBe(true);
});

it("should not set transform when not dragEnabled or resizable", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dialog open> test </calcite-dialog>`);
await skipAnimations(page);
await page.setViewport({ width: 1200, height: 1200 });
await page.waitForChanges();

const container = await page.find(`calcite-dialog >>> .${CSS.dialog}`);
expect((await container.getComputedStyle()).transform).toBe("none");
});

describe("keyboard movement", () => {
it("should move properly via arrow keys", async () => {
const page = await newE2EPage();
Expand All @@ -936,19 +947,19 @@ describe("calcite-dialog", () => {
await page.setViewport({ width: 1200, height: 1200 });
await page.waitForChanges();
const container = await page.find(`calcite-dialog >>> .${CSS.dialog}`);
expect((await container.getComputedStyle()).transform).toBe("matrix(1, 0, 0, 1, 0, 0)");
expect((await container.getComputedStyle()).transform).toBe("none");

await dispatchDialogKeydown({ page, key: "ArrowDown", shiftKey: false });
expect((await container.getComputedStyle()).transform).toBe(`matrix(1, 0, 0, 1, 0, ${dialogDragStep})`);

await dispatchDialogKeydown({ page, key: "ArrowUp", shiftKey: false });
expect((await container.getComputedStyle()).transform).toBe("matrix(1, 0, 0, 1, 0, 0)");
expect((await container.getComputedStyle()).transform).toBe("none");

await dispatchDialogKeydown({ page, key: "ArrowLeft", shiftKey: false });
expect((await container.getComputedStyle()).transform).toBe(`matrix(1, 0, 0, 1, -${dialogDragStep}, 0)`);

await dispatchDialogKeydown({ page, key: "ArrowRight", shiftKey: false });
expect((await container.getComputedStyle()).transform).toBe("matrix(1, 0, 0, 1, 0, 0)");
expect((await container.getComputedStyle()).transform).toBe("none");
});
});

Expand Down
10 changes: 9 additions & 1 deletion packages/calcite-components/src/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -609,18 +609,26 @@ export class Dialog
dragPosition: { x, y },
resizePosition,
transitionEl,
dragEnabled,
resizable,
} = this;

if (!transitionEl) {
return;
}

if (!dragEnabled && !resizable) {
transitionEl.style.transform = null;
return;
}

const { top, right, bottom, left } = this.getAdjustedResizePosition(resizePosition);

const translateX = Math.round(x + left + right);
const translateY = Math.round(y + top + bottom);

transitionEl.style.transform = `translate(${translateX}px, ${translateY}px)`;
transitionEl.style.transform =
translateX || translateY ? `translate(${translateX}px, ${translateY}px)` : null;
}

private updateSize({
Expand Down
Loading