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: fix jarring positioning when a closed component is first opened #5484

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
29 changes: 28 additions & 1 deletion src/components/popover/popover.stories.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { select, number, text } from "@storybook/addon-knobs";
import { html } from "../../../support/formatting";
import { boolean, storyFilters } from "../../../.storybook/helpers";
import { boolean, createSteps, stepStory, storyFilters } from "../../../.storybook/helpers";
import { placements } from "../../utils/floating-ui";
import readme from "./readme.md";
import { defaultPopoverPlacement } from "../popover/resources";
Expand Down Expand Up @@ -101,3 +101,30 @@ export const flipPlacements_TestOnly = (): string => html`
document.querySelector(".my-popover").flipPlacements = ["right"];
</script>
`;

export const correctInitialPosition_TestOnly = stepStory(
(): string => html`
<calcite-panel>
<button id="popover-button">Ref</button>
<calcite-popover
id="popover"
label="Example label"
reference-element="popover-button"
overlay-positioning="fixed"
>
<p style="padding:0 10px;display:flex;flex-direction:row">Floating</p>
</calcite-popover>
</calcite-panel>
`,
createSteps("calcite-popover")
.executeScript(
// we hijack styling to ensure initial positioning is captured in the screenshot
`
const popover = document.querySelector("calcite-popover");
popover.style = "border: 1px solid red";
popover.setAttribute("calcite-hydrated");
popover.removeAttribute("calcite-hydrated-hidden");
`
)
.snapshot("correct initial position")
);
3 changes: 3 additions & 0 deletions src/utils/floating-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ export function connectFloatingUI(

disconnectFloatingUI(component, referenceEl, floatingEl);

// ensure position matches for initial positioning
floatingEl.style.position = component.overlayPositioning;
Copy link
Member

Choose a reason for hiding this comment

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

👍


cleanupMap.set(
component,
autoUpdate(referenceEl, floatingEl, () => {
Expand Down