Skip to content

fix(input-date-picker): Correctly position open component when scrolling #6815

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

Merged
merged 6 commits into from
Apr 24, 2023
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
35 changes: 35 additions & 0 deletions src/components/input-date-picker/input-date-picker.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,41 @@ describe("calcite-input-date-picker", () => {
expect(await datepickerEl.getProperty("value")).toEqual(["2022-08-15", "2022-08-20"]);
});

it("should position on scroll when overlayPositioning is fixed", async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Could you try using commonTests#floatingUIOwner? It should cover scrolling updates.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test already has a floatingUIOwner test. Maybe it should be updated to test with overlay-positioning="fixed" as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried this and it passed so its not catching the issue.

 it("owns a floating-ui 2", () =>
    floatingUIOwner(
      `<calcite-input-date-picker overlay-positioning="fixed" value="2022-11-27" min="2022-11-15" max="2024-11-15"></calcite-input-date-picker>`,
      "open",
      { shadowSelector: ".menu-container" }
    ));

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... I think the helper might need some tweaking. Can you create a follow-up issue for me? Let's proceed with the existing test here.

Copy link
Member Author

Choose a reason for hiding this comment

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

created: #6838

const page = await newE2EPage();

await page.setContent(
html`<div id="scrollEl" style="max-height: 300px; height:300px; overflow: auto;">
<div style="height:100px"></div>
<calcite-input-date-picker open overlay-positioning="fixed"></calcite-input-date-picker>
<div style="height:400px"></div>
</div>`
);

await page.waitForChanges();

const scrollEl = await page.find("#scrollEl");

expect(await scrollEl.getProperty("scrollTop")).toBe(0);

const inputDatePicker = await page.find("calcite-input-date-picker");
const floatingEl = await page.find(`calcite-input-date-picker >>> .${CSS.menu}`);

expect(await inputDatePicker.isVisible()).toBe(true);
expect(await floatingEl.isVisible()).toBe(true);
expect((await floatingEl.getComputedStyle()).transform).toBe("matrix(1, 0, 0, 1, 8, 140)");

await page.$eval("#scrollEl", async (scrollEl: HTMLDivElement) => {
scrollEl.scrollTo({ top: 100 });
});

await page.waitForChanges();

expect(await inputDatePicker.isVisible()).toBe(true);
expect(await floatingEl.isVisible()).toBe(true);
expect((await floatingEl.getComputedStyle()).transform).toBe("matrix(1, 0, 0, 1, 8, 40)");
});

describe("focus trapping", () => {
it("traps focus only when open", async () => {
const page = await newE2EPage();
Expand Down
2 changes: 1 addition & 1 deletion src/components/input-date-picker/input-date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ export class InputDatePicker
? endWrapper || startWrapper
: startWrapper || endWrapper;

connectFloatingUI(this, this.referenceEl, this.floatingEl);
requestAnimationFrame(() => connectFloatingUI(this, this.referenceEl, this.floatingEl));
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to wait for next frame to connect floating UI because some rendering is still going on. The rendering needs to happen first before trying to get all scrollable parents.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. On a related note, I was thinking input-date-picker should be refactored to use popover for consistency and reusability. Maybe that would help eliminate since this doesn't appear to be an issue with the input-time-picker.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I think that makes sense since popover has a role of "dialog" and those two components seem to open dialogs. For things like combobox using the popover, we would need to be able to modify the role.

}

private valueAsDateChangedExternally = false;
Expand Down