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!: floating-ui elements no longer take up space when closed #10241

Merged
merged 56 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
356a0d5
fix: position floating-ui elements offscreen by default in order to p…
driskull Sep 6, 2024
bce13df
add story
driskull Sep 6, 2024
c4fde6e
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 6, 2024
0d41bc2
handle positioning with the util
driskull Sep 6, 2024
49c0b1e
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 9, 2024
10c8e1a
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 9, 2024
02ffbd4
set height and width to zero when not open.
driskull Sep 9, 2024
08b30f3
cleanup
driskull Sep 9, 2024
5451874
cleanup
driskull Sep 9, 2024
03090d3
cleanup
driskull Sep 9, 2024
2f2ef34
WIP
driskull Sep 9, 2024
90131c9
test
driskull Sep 9, 2024
1556b4a
testing
driskull Sep 9, 2024
1afd7eb
cleanup
driskull Sep 10, 2024
13d6904
revert
driskull Sep 11, 2024
ca9581a
review fixes
driskull Sep 11, 2024
f916680
move popover/tooltip styles from host to internal element. fix tests.
driskull Sep 11, 2024
6883e5d
fix some tests
driskull Sep 12, 2024
43817e4
cleanup
driskull Sep 12, 2024
5fe8d2e
tests
driskull Sep 12, 2024
402f2ff
fix test
driskull Sep 12, 2024
b31ec9e
fix more tests
driskull Sep 12, 2024
f198a28
cleanup tests
driskull Sep 12, 2024
d8838b1
cleanup
driskull Sep 12, 2024
6769cce
fix story
driskull Sep 12, 2024
87c2947
fix tests?
driskull Sep 12, 2024
5a4e810
cleanup
driskull Sep 12, 2024
6c02bfd
cleanup
driskull Sep 12, 2024
cee77ac
cleanup
driskull Sep 12, 2024
6c59d5e
tests
driskull Sep 12, 2024
48ea688
cleanup
driskull Sep 12, 2024
73bbedf
cleanup
driskull Sep 12, 2024
7294aa8
fix tests
driskull Sep 13, 2024
bf7568b
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 13, 2024
2ae9526
fix test
driskull Sep 13, 2024
eae0bb8
fix test
driskull Sep 13, 2024
966faa8
cleanup
driskull Sep 13, 2024
700e234
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 13, 2024
4998755
test fix
driskull Sep 13, 2024
f50a3fb
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 19, 2024
a681d1f
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 19, 2024
368d25c
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 25, 2024
86c2930
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Sep 26, 2024
a7e9241
Update .stylelintrc.cjs
driskull Sep 26, 2024
012c5c2
fix test
driskull Sep 26, 2024
1df132c
Merge branch 'dris0000/floating-ui-position-when-closed' of github.co…
driskull Sep 26, 2024
5e327f2
fix e2e
driskull Sep 26, 2024
e5d0977
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Oct 8, 2024
734f77c
fix build
driskull Oct 8, 2024
4b22a1a
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Oct 23, 2024
551249e
fix tests
driskull Oct 23, 2024
910dc08
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Oct 29, 2024
b7f921c
review fixes
driskull Oct 29, 2024
2839cc2
fix story
driskull Oct 31, 2024
681a46e
Merge branch 'dev' into dris0000/floating-ui-position-when-closed
driskull Oct 31, 2024
f740c9c
cleanup stories
driskull Oct 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $floating-ui-transition-offset: 5px;

@mixin floating-ui-anim-active {
opacity: 1;
inset-block: 0;
inset-block-start: 0;
left: 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ describe("calcite-dropdown", () => {
const page = await newE2EPage({
html: html`<calcite-panel heading="Issue #3048">
<calcite-pick-list filter-enabled>
<calcite-dropdown slot="menu-actions" placement="bottom-end" type="click">
<calcite-dropdown open slot="menu-actions" placement="bottom-end" type="click">
driskull marked this conversation as resolved.
Show resolved Hide resolved
<calcite-action slot="trigger" title="Sort" icon="sort-descending"> </calcite-action>
<calcite-dropdown-group selection-mode="single">
<calcite-dropdown-item>Display name</calcite-dropdown-item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,9 @@ export const transparentBG_TestOnly = (): string => html`
</calcite-popover>
</div>
`;

export const closedShouldNotCauseScrollbars = (): string =>
html`<calcite-popover reference-element="button">
<div style="width:10000px; height:10000px;">Popover</div>
</calcite-popover>
<calcite-button id="button">Button</calcite-button>`;
16 changes: 13 additions & 3 deletions packages/calcite-components/src/utils/floating-ui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,27 @@ describe("repositioning", () => {
connectFloatingUI(fakeFloatingUiComponent, referenceEl, floatingEl);
});

function assertClosedPositioning(floatingEl: HTMLElement): void {
expect(floatingEl.style.display).toBe("none");
driskull marked this conversation as resolved.
Show resolved Hide resolved
}

function assertPreOpenPositioning(floatingEl: HTMLElement): void {
expect(floatingEl.style.transform).toBe("");
expect(floatingEl.style.top).toBe("");
expect(floatingEl.style.left).toBe("");
expect(floatingEl.style.top).toBe("0");
expect(floatingEl.style.left).toBe("0");
expect(floatingEl.style.display).toBe("");
}

function assertOpenPositioning(floatingEl: HTMLElement): void {
expect(floatingEl.style.transform).not.toBe("");
expect(floatingEl.style.top).toBe("0");
expect(floatingEl.style.left).toBe("0");
expect(floatingEl.style.display).toBe("");
}

it("repositions only for open components", async () => {
await reposition(fakeFloatingUiComponent, positionOptions);
assertPreOpenPositioning(floatingEl);
assertClosedPositioning(floatingEl);

fakeFloatingUiComponent.open = true;

Expand All @@ -101,6 +107,8 @@ describe("repositioning", () => {
});

it("repositions immediately by default", async () => {
assertClosedPositioning(floatingEl);

fakeFloatingUiComponent.open = true;

reposition(fakeFloatingUiComponent, positionOptions);
Expand All @@ -112,6 +120,8 @@ describe("repositioning", () => {
});

it("can reposition after a delay", async () => {
assertClosedPositioning(floatingEl);

fakeFloatingUiComponent.open = true;

reposition(fakeFloatingUiComponent, positionOptions, true);
Expand Down
38 changes: 27 additions & 11 deletions packages/calcite-components/src/utils/floating-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,16 @@ export const positionFloatingUI =

const { open } = component;

if (!open) {
Object.assign(floatingEl.style, hiddenFloatingElStyle);
driskull marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Object.assign(floatingEl.style, {
visibility,
pointerEvents,
position,
transform: open ? `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)` : "",
top: 0,
left: 0,
transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
});
};

Expand Down Expand Up @@ -408,6 +411,18 @@ export function getEffectivePlacement(placement: LogicalPlacement, isRTL = false
return placement.replace(/leading/gi, placements[0]).replace(/trailing/gi, placements[1]) as EffectivePlacement;
}

const initialFloatingElStyle = {
display: "",
// initial positioning based on https://floating-ui.com/docs/computePosition#initial-layout
position: "absolute",
top: "0",
left: "0",
};

const hiddenFloatingElStyle = {
display: "none",
};

/**
* Convenience function to manage `reposition` calls for FloatingUIComponents that use `positionFloatingUI.
*
Expand All @@ -433,10 +448,17 @@ export async function reposition(
options: Parameters<typeof positionFloatingUI>[1],
delayed = false,
): Promise<void> {
if (!component.open || !options.floatingEl || !options.referenceEl) {
if (!options.floatingEl) {
return;
}

if (!component.open || !options.referenceEl) {
Object.assign(options.floatingEl.style, hiddenFloatingElStyle);
return;
}

Object.assign(options.floatingEl.style, initialFloatingElStyle);
driskull marked this conversation as resolved.
Show resolved Hide resolved

const trackedState = autoUpdatingComponentMap.get(component);

if (!trackedState) {
Expand Down Expand Up @@ -551,13 +573,7 @@ export async function connectFloatingUI(

disconnectFloatingUI(component, referenceEl, floatingEl);

Object.assign(floatingEl.style, {
visibility: "hidden",
pointerEvents: "none",

// initial positioning based on https://floating-ui.com/docs/computePosition#initial-layout
position: component.overlayPositioning,
});
Object.assign(floatingEl.style, hiddenFloatingElStyle);

if (!component.open) {
return;
Expand Down
Loading