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

refactor(combobox): address post-commit review comments #11540

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
112 changes: 74 additions & 38 deletions packages/calcite-components/src/components/combobox/combobox.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2572,49 +2572,43 @@ describe("calcite-combobox", () => {
"item3",
));

it("shows the selected item when initially opened", async () => {
it("shows the selected item when initially opened with single selection", async () => {
const page = await newE2EPage();

await page.setContent(`
<calcite-combobox
open
id="labelOne"
label="test"
placeholder="selected element (Black Eyed Susan) should be in view"
max-items="6"
selection-mode="single"
>
<calcite-combobox-item value="Trees" text-label="Trees">
<calcite-combobox-item value="Pine" text-label="Pine">
<calcite-combobox-item value="Pine Nested" text-label="Pine Nested"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Sequoia" disabled text-label="Sequoia"></calcite-combobox-item>
<calcite-combobox-item value="Douglas Fir" text-label="Douglas Fir"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Flowers" text-label="Flowers">
<calcite-combobox-item value="Daffodil" text-label="Daffodil"></calcite-combobox-item>
<calcite-combobox-item
value="Black Eyed Susan"
text-label="Black Eyed Susan"
selected
></calcite-combobox-item>
<calcite-combobox-item value="Nasturtium" text-label="Nasturtium"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Animals" text-label="Animals">
<calcite-combobox-item value="Birds" text-label="Birds"></calcite-combobox-item>
<calcite-combobox-item value="Reptiles" text-label="Reptiles"></calcite-combobox-item>
<calcite-combobox-item value="Amphibians" text-label="Amphibians"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Rocks" text-label="Rocks"></calcite-combobox-item>
<calcite-combobox-item value="Insects" text-label="Insects"></calcite-combobox-item>
<calcite-combobox-item value="Rivers" text-label="Rivers"></calcite-combobox-item>
</calcite-combobox>
`);
await page.setContent(
html`<calcite-combobox open max-items="6" selection-mode="single">
<calcite-combobox-item value="Trees" text-label="Trees">
<calcite-combobox-item value="Pine" text-label="Pine">
<calcite-combobox-item value="Pine Nested" text-label="Pine Nested"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Sequoia" disabled text-label="Sequoia"></calcite-combobox-item>
<calcite-combobox-item value="Douglas Fir" text-label="Douglas Fir"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Flowers" text-label="Flowers">
<calcite-combobox-item value="Daffodil" text-label="Daffodil"></calcite-combobox-item>
<calcite-combobox-item
value="Black Eyed Susan"
text-label="Black Eyed Susan"
selected
></calcite-combobox-item>
<calcite-combobox-item value="Nasturtium" text-label="Nasturtium"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Animals" text-label="Animals">
<calcite-combobox-item value="Birds" text-label="Birds"></calcite-combobox-item>
<calcite-combobox-item value="Reptiles" text-label="Reptiles"></calcite-combobox-item>
<calcite-combobox-item value="Amphibians" text-label="Amphibians"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Rocks" text-label="Rocks"></calcite-combobox-item>
<calcite-combobox-item value="Insects" text-label="Insects"></calcite-combobox-item>
<calcite-combobox-item value="Rivers" text-label="Rivers"></calcite-combobox-item>
</calcite-combobox>`,
);
await page.waitForChanges();
const combobox = await page.find("calcite-combobox");
const item1 = await combobox.find("calcite-combobox-item[value='Black Eyed Susan']");
const selectedItem = await combobox.find("calcite-combobox-item[value='Black Eyed Susan']");

expect(await item1.isIntersectingViewport()).toBeTruthy();
expect(await selectedItem.isIntersectingViewport()).toBeTruthy();
expect(await selectedItem.getProperty("selected")).toBeTruthy();
});
});

Expand All @@ -2638,6 +2632,48 @@ describe("calcite-combobox", () => {
</calcite-combobox>`,
"item3",
));

it("shows the selected item when initially opened with multiple selection", async () => {
const page = await newE2EPage();

await page.setContent(
html`<calcite-combobox open max-items="6" selection-mode="multiple">
<calcite-combobox-item value="Trees" text-label="Trees">
<calcite-combobox-item value="Pine" text-label="Pine">
<calcite-combobox-item value="Pine Nested" text-label="Pine Nested"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Sequoia" disabled text-label="Sequoia"></calcite-combobox-item>
<calcite-combobox-item value="Douglas Fir" text-label="Douglas Fir"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Flowers" text-label="Flowers">
<calcite-combobox-item value="Daffodil" text-label="Daffodil"></calcite-combobox-item>
<calcite-combobox-item
value="Black Eyed Susan"
text-label="Black Eyed Susan"
selected
></calcite-combobox-item>
<calcite-combobox-item value="Nasturtium" text-label="Nasturtium"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Animals" text-label="Animals">
<calcite-combobox-item value="Birds" text-label="Birds"></calcite-combobox-item>
<calcite-combobox-item value="Reptiles" text-label="Reptiles"></calcite-combobox-item>
<calcite-combobox-item value="Amphibians" text-label="Amphibians"></calcite-combobox-item>
</calcite-combobox-item>
<calcite-combobox-item value="Rocks" text-label="Rocks" selected></calcite-combobox-item>
<calcite-combobox-item value="Insects" text-label="Insects"></calcite-combobox-item>
<calcite-combobox-item value="Rivers" text-label="Rivers"></calcite-combobox-item>
</calcite-combobox>`,
);
await page.waitForChanges();
const combobox = await page.find("calcite-combobox");
const firstSelectedItem = await combobox.find("calcite-combobox-item[value='Black Eyed Susan']");
const secondSelectedItem = await combobox.find("calcite-combobox-item[value='Rocks']");

expect(await firstSelectedItem.isIntersectingViewport()).toBeTruthy();
expect(await secondSelectedItem.isIntersectingViewport()).toBeFalsy();
expect(await firstSelectedItem.getProperty("selected")).toBeTruthy();
expect(await secondSelectedItem.getProperty("selected")).toBeTruthy();
});
});

describe("ancestors-selection", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ export class Combobox

private scrollToActiveOrSelectedItem(scrollToSelected = false): void {
const item =
scrollToSelected && this.selectedItems && this.selectedItems.length
scrollToSelected && this.selectedItems?.length
? this.selectedItems[0]
: this.filteredItems[this.activeItemIndex];

Expand Down
Loading