Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/calcite-components/.stylelintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const customFunctions = [
"medium-modular-scale",
"modular-scale",
"scale-duration",
"small-modular-scale",
"small-modular-scale"
];
// ⚠️ END OF AUTO-GENERATED CODE

Expand Down
49 changes: 4 additions & 45 deletions packages/calcite-components/src/assets/styles/_floating-ui.scss
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 Expand Up @@ -64,54 +64,13 @@ $floating-ui-transition-offset: 5px;
}
}

@mixin floating-ui-host-anim {
@include floating-ui-anim();

:host([data-placement^="bottom"]) .calcite-floating-ui-anim {
@include floating-ui-offset-bottom();
}

:host([data-placement^="top"]) .calcite-floating-ui-anim {
@include floating-ui-offset-top();
}

:host([data-placement^="left"]) .calcite-floating-ui-anim {
@include floating-ui-offset-left();
}

:host([data-placement^="right"]) .calcite-floating-ui-anim {
@include floating-ui-offset-right();
}

:host([data-placement]) .calcite-floating-ui-anim--active {
@include floating-ui-anim-active();
}
}

@mixin floating-ui-container() {
display: block;
position: absolute;
display: none;
inset-block-start: 0;
left: 0;
z-index: var(--calcite-floating-ui-z-index);
}

@mixin floating-ui-wrapper {
visibility: hidden;
}

@mixin floating-ui-wrapper-active {
visibility: visible;
}

@mixin floating-ui-host() {
:host {
@include floating-ui-container();
}

@include floating-ui-host-anim();

@include calcite-hydrated-hidden();
}

@mixin floating-ui-arrow {
.calcite-floating-ui-arrow {
@apply -z-default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
themed,
} from "../../tests/commonTests";
import { TOOLTIP_OPEN_DELAY_MS } from "../tooltip/resources";
import { CSS as TooltipCSS } from "../tooltip/resources";
import { skipAnimations } from "../../tests/utils";
import { CSS, SLOTS, activeAttr } from "./resources";

describe("calcite-action-menu", () => {
Expand Down Expand Up @@ -212,31 +214,33 @@ describe("calcite-action-menu", () => {
});

it("should close tooltip when open", async () => {
const page = await newE2EPage({
html: `
<calcite-action-menu label="test">
<calcite-action id="trigger" slot="${SLOTS.trigger}" text="Add" icon="plus"></calcite-action>
<calcite-tooltip slot="${SLOTS.tooltip}">Bits and bobs.</calcite-tooltip>
<calcite-action text="Add" icon="plus"></calcite-action>
</calcite-action-menu>
`,
});
const page = await newE2EPage();

await page.setContent(html`
<calcite-action-menu label="test">
<calcite-action id="trigger" slot="${SLOTS.trigger}" text="Add" icon="plus"></calcite-action>
<calcite-tooltip slot="${SLOTS.tooltip}">Bits and bobs.</calcite-tooltip>
<calcite-action text="Add" icon="plus"></calcite-action>
</calcite-action-menu>
`);

await skipAnimations(page);

const actionMenu = await page.find("calcite-action-menu");
const tooltip = await page.find("calcite-tooltip");
const tooltipPositionContainer = await page.find(`calcite-tooltip >>> .${TooltipCSS.positionContainer}`);
const trigger = await page.find("#trigger");

expect(await tooltip.isVisible()).toBe(false);
expect(await tooltipPositionContainer.isVisible()).toBe(false);

await trigger.hover();
await page.waitForTimeout(TOOLTIP_OPEN_DELAY_MS);

expect(await tooltip.isVisible()).toBe(true);
expect(await tooltipPositionContainer.isVisible()).toBe(true);

actionMenu.setProperty("open", true);
await page.waitForChanges();

expect(await tooltip.isVisible()).toBe(false);
expect(await tooltipPositionContainer.isVisible()).toBe(false);
});

describe("Keyboard navigation", () => {
Expand Down
30 changes: 15 additions & 15 deletions packages/calcite-components/src/components/combobox/combobox.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ describe("calcite-combobox", () => {
await page.waitForChanges();
expect(await page.evaluate(() => document.activeElement.id)).toBe("myCombobox");

const container = await page.find(`#myCombobox >>> .floating-ui-container`);
const container = await page.find(`#myCombobox >>> .${CSS.floatingUIContainer}`);
const visible = await container.isVisible();
expect(visible).toBe(false);
});
Expand All @@ -1361,25 +1361,25 @@ describe("calcite-combobox", () => {
await page.keyboard.press("Tab");
expect(await page.evaluate(() => document.activeElement.id)).toBe("myCombobox");

const floatingUI = await page.find("#myCombobox >>> .floating-ui-container--active");
expect(floatingUI).toBeNull();
const floatingUI = await page.find(`#myCombobox >>> .${CSS.floatingUIContainer}`);
expect(await floatingUI.isVisible()).toBe(false);
});

it("tab will close the item group if it’s open", async () => {
skipAnimations(page);
const inputEl = await page.find(`#myCombobox >>> input`);
await inputEl.focus();
await page.waitForChanges();
expect(await page.evaluate(() => document.activeElement.id)).toBe("myCombobox");

await page.keyboard.press("Space");
await page.waitForChanges();
let floatingUI = await page.find("#myCombobox >>> .floating-ui-container--active");
expect(floatingUI).toBeTruthy();
const floatingUI = await page.find(`#myCombobox >>> .${CSS.floatingUIContainer}`);
expect(await floatingUI.isVisible()).toBe(true);

await page.keyboard.press("Tab");
await page.waitForChanges();
floatingUI = await page.find("#myCombobox >>> .floating-ui-container--active");
expect(floatingUI).toBeNull();
expect(await floatingUI.isVisible()).toBe(false);
});

it("should not throw when typing custom value and pressing ArrowDown", async () => {
Expand Down Expand Up @@ -1409,20 +1409,20 @@ describe("calcite-combobox", () => {
});

it(`Escape closes the dropdown, but remains focused`, async () => {
await skipAnimations(page);
const inputEl = await page.find(`#myCombobox >>> input`);
await inputEl.focus();
await page.waitForChanges();
expect(await page.evaluate(() => document.activeElement.id)).toBe("myCombobox");

await page.keyboard.press("Space");
await page.waitForChanges();
let floatingUI = await page.find("#myCombobox >>> .floating-ui-container--active");
expect(floatingUI).toBeTruthy();
const floatingUI = await page.find(`#myCombobox >>> .${CSS.floatingUIContainer}`);
expect(await floatingUI.isVisible()).toBe(true);

await page.keyboard.press("Escape");
await page.waitForChanges();
floatingUI = await page.find("#myCombobox >>> .floating-ui-container--active");
expect(floatingUI).toBeNull();
expect(await floatingUI.isVisible()).toBe(false);

expect(await page.evaluate(() => document.activeElement.id)).toBe("myCombobox");
});
Expand Down Expand Up @@ -1464,8 +1464,8 @@ describe("calcite-combobox", () => {
});
const combobox = await page.find("calcite-combobox");
await combobox.callMethod(`setFocus`);
const activeContainer = await page.find("#myCombobox >>> .floating-ui-container--active");
expect(activeContainer).toBeNull();
const floatingUI = await page.find(`#myCombobox >>> .${CSS.floatingUIContainer}`);
expect(await floatingUI.isVisible()).toBe(false);
expect(await page.evaluate(() => window.scrollY)).toEqual(0);

await page.keyboard.press("PageDown");
Expand Down Expand Up @@ -1907,7 +1907,7 @@ describe("calcite-combobox", () => {
expect(value).toBe("");
await input.click();

const container = await page.find("calcite-combobox >>> .floating-ui-container");
const container = await page.find(`calcite-combobox >>> .${CSS.floatingUIContainer}`);
let visible = await container.isVisible();
expect(visible).toBe(true);

Expand Down Expand Up @@ -2055,7 +2055,7 @@ describe("calcite-combobox", () => {
</calcite-combobox>
`,
"open",
{ shadowSelector: ".floating-ui-container" },
{ shadowSelector: `.${CSS.floatingUIContainer}` },
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,13 @@
.floating-ui-container {
--calcite-floating-ui-z-index: theme("zIndex.dropdown");
@include floating-ui-container();
@include floating-ui-wrapper();
}

@include floating-ui-elem-anim(".floating-ui-container");

.floating-ui-container--active {
@include floating-ui-wrapper-active();
}

@media (forced-colors: active) {
.wrapper,
.floating-ui-container--active {
.floating-ui-container {
border: 1px solid canvasText;
}
}
Expand Down
29 changes: 12 additions & 17 deletions packages/calcite-components/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
FlipPlacement,
FloatingCSS,
FloatingUIComponent,
hideFloatingUI,
LogicalPlacement,
OverlayPositioning,
reposition,
Expand Down Expand Up @@ -499,7 +500,7 @@ export class Combobox
onToggleOpenCloseComponent(this);
}

connectFloatingUI(this, this.referenceEl, this.floatingEl);
connectFloatingUI(this);
}

async componentWillLoad(): Promise<void> {
Expand All @@ -511,7 +512,7 @@ export class Combobox

componentDidLoad(): void {
afterConnectDefaultValueSet(this, this.getValue());
connectFloatingUI(this, this.referenceEl, this.floatingEl);
connectFloatingUI(this);
setComponentLoaded(this);
}

Expand All @@ -533,7 +534,7 @@ export class Combobox
this.resizeObserver?.disconnect();
disconnectLabel(this);
disconnectForm(this);
disconnectFloatingUI(this, this.referenceEl, this.floatingEl);
disconnectFloatingUI(this);
disconnectLocalized(this);
disconnectMessages(this);
}
Expand Down Expand Up @@ -591,6 +592,10 @@ export class Combobox

textInput: HTMLInputElement = null;

floatingEl: HTMLDivElement;

referenceEl: HTMLDivElement;

private data: ItemData[];

mutationObserver = createObserver("mutation", () => this.updateItems());
Expand All @@ -604,10 +609,6 @@ export class Combobox

private inputHeight = 0;

private floatingEl: HTMLDivElement;

private referenceEl: HTMLDivElement;

private chipContainerEl: HTMLDivElement;

private listContainerEl: HTMLDivElement;
Expand Down Expand Up @@ -826,6 +827,7 @@ export class Combobox

onClose(): void {
this.calciteComboboxClose.emit();
hideFloatingUI(this);
}

setMaxScrollerHeight = async (): Promise<void> => {
Expand Down Expand Up @@ -972,7 +974,7 @@ export class Combobox

setFloatingEl = (el: HTMLDivElement): void => {
this.floatingEl = el;
connectFloatingUI(this, this.referenceEl, this.floatingEl);
connectFloatingUI(this);
};

private setCompactSelectionDisplay({
Expand Down Expand Up @@ -1003,7 +1005,7 @@ export class Combobox

setReferenceEl = (el: HTMLDivElement): void => {
this.referenceEl = el;
connectFloatingUI(this, this.referenceEl, this.floatingEl);
connectFloatingUI(this);
};

setAllSelectedIndicatorChipEl = (el: HTMLCalciteChipElement): void => {
Expand Down Expand Up @@ -1676,14 +1678,7 @@ export class Combobox
};

return (
<div
aria-hidden="true"
class={{
"floating-ui-container": true,
"floating-ui-container--active": open,
}}
ref={setFloatingEl}
>
<div aria-hidden="true" class={CSS.floatingUIContainer} ref={setFloatingEl}>
<div class={classes} ref={setContainerEl}>
<ul class={{ list: true, "list--hide": !open }}>
<slot />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const CSS = {
icon: "icon",
placeholderIcon: "placeholder-icon",
selectedIcon: "selected-icon",
floatingUIContainer: "floating-ui-container",
};

export const IDS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ describe("calcite-dropdown", () => {
</calcite-dropdown-group>
</calcite-dropdown>
`);
await skipAnimations(page);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("calcite-button[slot='trigger']");
const dropdownWrapper = await page.find(`calcite-dropdown >>> .calcite-dropdown-wrapper`);
Expand Down Expand Up @@ -779,6 +780,7 @@ describe("calcite-dropdown", () => {
</calcite-dropdown-group>
</calcite-dropdown>
`);
await skipAnimations(page);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("calcite-action[slot='trigger'] >>> button");
const dropdownWrapper = await page.find(`calcite-dropdown >>> .calcite-dropdown-wrapper`);
Expand Down Expand Up @@ -825,6 +827,7 @@ describe("calcite-dropdown", () => {
</calcite-dropdown-group>
</calcite-dropdown>
`);
await skipAnimations(page);
const element = await page.find("calcite-dropdown");
const dropdownWrapper = await page.find(`calcite-dropdown >>> .calcite-dropdown-wrapper`);
const calciteDropdownOpen = await element.spyOnEvent("calciteDropdownOpen");
Expand Down Expand Up @@ -1163,6 +1166,7 @@ describe("calcite-dropdown", () => {
</calcite-list>
</calcite-panel>`,
});
await skipAnimations(page);
await page.waitForChanges();

const dropdownContentHeight = await (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
:host .calcite-dropdown-wrapper {
--calcite-floating-ui-z-index: theme("zIndex.dropdown");
@include floating-ui-container();
@include floating-ui-wrapper();
}

@include floating-ui-elem-anim(".calcite-dropdown-wrapper");
:host([open]) .calcite-dropdown-wrapper {
@include floating-ui-wrapper-active();
}

:host .calcite-dropdown-content {
@apply bg-foreground-1
Expand Down
Loading