Skip to content

Commit c80c44c

Browse files
Elijbetbenelan
authored andcommitted
feat(list-item, list): add expanded property and deprecate open property (#11003)
**Related Issue:** #6473, #11225 ## Summary Deprecate `open` prop in favor of `expanded`. Add logger warning for deprecation to help inform users about the deprecated property and guide them towards using the recommended alternatives.
1 parent 3800b36 commit c80c44c

File tree

9 files changed

+244
-177
lines changed

9 files changed

+244
-177
lines changed

packages/calcite-components/src/components/list-item/list-item.e2e.ts

+82-34
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ describe("calcite-list-item", () => {
4545
propertyName: "open",
4646
defaultValue: false,
4747
},
48+
{
49+
propertyName: "expanded",
50+
defaultValue: false,
51+
},
52+
{
53+
propertyName: "closed",
54+
defaultValue: false,
55+
},
56+
{
57+
propertyName: "closable",
58+
defaultValue: false,
59+
},
4860
{
4961
propertyName: "dragHandle",
5062
defaultValue: false,
@@ -90,6 +102,22 @@ describe("calcite-list-item", () => {
90102
propertyName: "sortHandleOpen",
91103
value: true,
92104
},
105+
{
106+
propertyName: "open",
107+
value: true,
108+
},
109+
{
110+
propertyName: "expanded",
111+
value: true,
112+
},
113+
{
114+
propertyName: "closed",
115+
value: true,
116+
},
117+
{
118+
propertyName: "closable",
119+
value: true,
120+
},
93121
]);
94122
});
95123

@@ -370,50 +398,69 @@ describe("calcite-list-item", () => {
370398
expect(calciteListItemClose).toHaveReceivedEventTimes(1);
371399
});
372400

373-
it("should fire calciteListItemToggle event when opened and closed", async () => {
374-
const page = await newE2EPage({
375-
html: html`<calcite-list-item id="test" display-mode="nested"
376-
><calcite-list display-mode="nested"><calcite-list-item></calcite-list-item></calcite-list
377-
></calcite-list-item>`,
401+
describe("calciteListItemToggle event", () => {
402+
it("should fire calciteListItemToggle event when expanded and collapsed", async () => {
403+
const page = await newE2EPage({
404+
html: html`<calcite-list-item id="test" display-mode="nested"
405+
><calcite-list display-mode="nested"><calcite-list-item></calcite-list-item></calcite-list
406+
></calcite-list-item>`,
407+
});
408+
409+
const listItem = await page.find("#test");
410+
const calciteListItemToggle = await page.spyOnEvent("calciteListItemToggle", "window");
411+
412+
expect(await listItem.getProperty("expanded")).toBe(false);
413+
414+
const expandedButton = await page.find(`#test >>> .${CSS.expandedContainer}`);
415+
416+
await expandedButton.click();
417+
expect(await listItem.getProperty("expanded")).toBe(true);
418+
expect(calciteListItemToggle).toHaveReceivedEventTimes(1);
419+
420+
await expandedButton.click();
421+
expect(await listItem.getProperty("expanded")).toBe(false);
422+
expect(calciteListItemToggle).toHaveReceivedEventTimes(2);
378423
});
379424

380-
const listItem = await page.find("#test");
381-
const calciteListItemToggle = await page.spyOnEvent("calciteListItemToggle", "window");
425+
it("should not fire calciteListItemToggle event without nested items", async () => {
426+
const page = await newE2EPage({
427+
html: html`<calcite-list-item display-mode="nested"></calcite-list-item>`,
428+
});
382429

383-
expect(await listItem.getProperty("open")).toBe(false);
430+
const listItem = await page.find("calcite-list-item");
431+
const calciteListItemToggle = await page.spyOnEvent("calciteListItemToggle", "window");
384432

385-
const openButton = await page.find(`#test >>> .${CSS.openContainer}`);
433+
expect(await listItem.getProperty("expanded")).toBe(false);
386434

387-
await openButton.click();
388-
expect(await listItem.getProperty("open")).toBe(true);
389-
expect(calciteListItemToggle).toHaveReceivedEventTimes(1);
435+
const expandedButton = await page.find(`calcite-list-item >>> .${CSS.expandedContainer}`);
390436

391-
await openButton.click();
392-
expect(await listItem.getProperty("open")).toBe(false);
393-
expect(calciteListItemToggle).toHaveReceivedEventTimes(2);
437+
expect(expandedButton.getAttribute("title")).toBe(null);
438+
439+
await expandedButton.click();
440+
expect(await listItem.getProperty("expanded")).toBe(false);
441+
expect(calciteListItemToggle).toHaveReceivedEventTimes(0);
442+
443+
await expandedButton.click();
444+
expect(await listItem.getProperty("expanded")).toBe(false);
445+
expect(calciteListItemToggle).toHaveReceivedEventTimes(0);
446+
});
394447
});
395448

396-
it("should not fire calciteListItemToggle event without nested items", async () => {
449+
// Broader functionality related to the 'expanded' prop is covered in the `expanded` tests.
450+
it("should map deprecated 'open' prop to 'expanded' prop", async () => {
397451
const page = await newE2EPage({
398-
html: html`<calcite-list-item display-mode="nested"></calcite-list-item>`,
452+
html: html`<calcite-list-item></calcite-list-item>`,
399453
});
400-
401454
const listItem = await page.find("calcite-list-item");
402-
const calciteListItemToggle = await page.spyOnEvent("calciteListItemToggle", "window");
403-
404-
expect(await listItem.getProperty("open")).toBe(false);
455+
expect(await listItem.getProperty("expanded")).toBe(false);
405456

406-
const openButton = await page.find(`calcite-list-item >>> .${CSS.openContainer}`);
407-
408-
expect(openButton.getAttribute("title")).toBe(null);
409-
410-
await openButton.click();
411-
expect(await listItem.getProperty("open")).toBe(false);
412-
expect(calciteListItemToggle).toHaveReceivedEventTimes(0);
457+
listItem.setProperty("open", true);
458+
await page.waitForChanges();
459+
expect(await listItem.getProperty("expanded")).toBe(true);
413460

414-
await openButton.click();
415-
expect(await listItem.getProperty("open")).toBe(false);
416-
expect(calciteListItemToggle).toHaveReceivedEventTimes(0);
461+
listItem.setProperty("open", false);
462+
await page.waitForChanges();
463+
expect(await listItem.getProperty("expanded")).toBe(false);
417464
});
418465

419466
it("should set displayMode on slotted list", async () => {
@@ -438,16 +485,16 @@ describe("calcite-list-item", () => {
438485
expect(await list.getProperty("displayMode")).toBe("flat");
439486
});
440487

441-
it("flat list should not render open container", async () => {
488+
it("flat list should not render expanded container", async () => {
442489
const page = await newE2EPage({
443490
html: html`<calcite-list-item display-mode="flat"
444491
><calcite-list><calcite-list-item></calcite-list-item></calcite-list
445492
></calcite-list-item>`,
446493
});
447494

448-
const openButton = await page.find(`calcite-list-item >>> .${CSS.openContainer}`);
495+
const expandedButton = await page.find(`calcite-list-item >>> .${CSS.expandedContainer}`);
449496

450-
expect(openButton).toBe(null);
497+
expect(expandedButton).toBe(null);
451498
});
452499

453500
it("renders with iconStart", async () => {
@@ -526,6 +573,7 @@ describe("calcite-list-item", () => {
526573
},
527574
);
528575
});
576+
529577
describe(`selection-appearance="border"`, () => {
530578
themed(
531579
html`<calcite-list-item

packages/calcite-components/src/components/list-item/list-item.scss

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
margin-inline-start: var(--calcite-list-spacing-indent, theme("spacing.6"));
8585
}
8686

87-
.nested-container--open {
87+
.nested-container--expanded {
8888
@apply flex;
8989
}
9090

@@ -373,12 +373,12 @@
373373
@apply flex-initial;
374374
}
375375

376-
.open-container {
376+
.expanded-container {
377377
color: var(--calcite-list-icon-color, var(--calcite-color-text-3));
378378
padding-inline: var(--calcite-spacing-xxs);
379379
}
380380

381-
:host(:not([disabled])) .container:hover .open-container {
381+
:host(:not([disabled])) .container:hover .expanded-container {
382382
color: var(--calcite-list-icon-color, var(--calcite-color-text-1));
383383
}
384384

@@ -388,7 +388,7 @@
388388
.content-end,
389389
.selection-container,
390390
.drag-container,
391-
.open-container {
391+
.expanded-container {
392392
@apply flex items-center;
393393

394394
calcite-action,
@@ -397,7 +397,7 @@
397397
}
398398
}
399399

400-
.open-container,
400+
.expanded-container,
401401
.selection-container {
402402
@apply cursor-pointer;
403403
}

0 commit comments

Comments
 (0)