diff --git a/packages/calcite-components/src/components.d.ts b/packages/calcite-components/src/components.d.ts index 68d4f03e98e..4f139615644 100644 --- a/packages/calcite-components/src/components.d.ts +++ b/packages/calcite-components/src/components.d.ts @@ -3312,6 +3312,10 @@ export namespace Components { * Used to specify the aria-setsize attribute to define the number of items in the current set of list for accessibility. */ "setSize": number; + /** + * When `true`, the component's content appears inactive. + */ + "unavailable": boolean; /** * The component's value. */ @@ -11440,6 +11444,10 @@ declare namespace LocalJSX { * Used to specify the aria-setsize attribute to define the number of items in the current set of list for accessibility. */ "setSize"?: number; + /** + * When `true`, the component's content appears inactive. + */ + "unavailable"?: boolean; /** * The component's value. */ diff --git a/packages/calcite-components/src/components/list-item/list-item.e2e.ts b/packages/calcite-components/src/components/list-item/list-item.e2e.ts index f053f7b303f..c99dc7039dd 100755 --- a/packages/calcite-components/src/components/list-item/list-item.e2e.ts +++ b/packages/calcite-components/src/components/list-item/list-item.e2e.ts @@ -1,5 +1,5 @@ import { newE2EPage } from "@stencil/core/testing"; -import { defaults, disabled, focusable, hidden, renders, slots } from "../../tests/commonTests"; +import { defaults, disabled, focusable, hidden, reflects, renders, slots } from "../../tests/commonTests"; import { html } from "../../../support/formatting"; import { CSS, SLOTS } from "./resources"; @@ -56,6 +56,19 @@ describe("calcite-list-item", () => { propertyName: "filterHidden", defaultValue: false, }, + { + propertyName: "unavailable", + defaultValue: false, + }, + ]); + }); + + describe("reflects", () => { + reflects("calcite-list-item", [ + { + propertyName: "unavailable", + value: true, + }, ]); }); @@ -75,6 +88,20 @@ describe("calcite-list-item", () => { expect(await page.find(`calcite-list-item >>> .${CSS.containerHover}`)).not.toBeNull(); }); + it("adds unavailable class", async () => { + const page = await newE2EPage(); + await page.setContent(``); + await page.waitForChanges(); + + expect(await page.find(`calcite-list-item >>> .${CSS.contentContainerUnavailable}`)).toBeNull(); + + const item = await page.find("calcite-list-item"); + item.setProperty("unavailable", true); + await page.waitForChanges(); + + expect(await page.find(`calcite-list-item >>> .${CSS.contentContainerUnavailable}`)).not.toBeNull(); + }); + it("renders dragHandle when property is true", async () => { const page = await newE2EPage(); await page.setContent(``); diff --git a/packages/calcite-components/src/components/list-item/list-item.scss b/packages/calcite-components/src/components/list-item/list-item.scss index 2c40a7a9b2e..b2e7935a91e 100755 --- a/packages/calcite-components/src/components/list-item/list-item.scss +++ b/packages/calcite-components/src/components/list-item/list-item.scss @@ -75,6 +75,10 @@ p-0; } +.content-container--unavailable { + @apply opacity-disabled; +} + tr, td { @apply focus-base; diff --git a/packages/calcite-components/src/components/list-item/list-item.tsx b/packages/calcite-components/src/components/list-item/list-item.tsx index 6485bd03225..660b100eb8a 100644 --- a/packages/calcite-components/src/components/list-item/list-item.tsx +++ b/packages/calcite-components/src/components/list-item/list-item.tsx @@ -196,6 +196,11 @@ export class ListItem this.calciteInternalListItemSelect.emit(); } + /** + * When `true`, the component's content appears inactive. + */ + @Prop({ reflect: true }) unavailable = false; + /** * The component's value. */ @@ -613,7 +618,7 @@ export class ListItem } renderContentContainer(): VNode { - const { description, label, selectionMode, hasCustomContent } = this; + const { description, label, selectionMode, hasCustomContent, unavailable } = this; const hasCenterContent = hasCustomContent || !!label || !!description; const content = [ this.renderContentStart(), @@ -627,6 +632,7 @@ export class ListItem aria-label={label} class={{ [CSS.contentContainer]: true, + [CSS.contentContainerUnavailable]: unavailable, [CSS.contentContainerSelectable]: selectionMode !== "none", [CSS.contentContainerHasCenterContent]: hasCenterContent, }} diff --git a/packages/calcite-components/src/components/list-item/resources.ts b/packages/calcite-components/src/components/list-item/resources.ts index 64609366ca1..115ba5b315d 100644 --- a/packages/calcite-components/src/components/list-item/resources.ts +++ b/packages/calcite-components/src/components/list-item/resources.ts @@ -7,6 +7,7 @@ export const CSS = { containerBorderSelected: "container--border-selected", containerBorderUnselected: "container--border-unselected", contentContainer: "content-container", + contentContainerUnavailable: "content-container--unavailable", contentContainerSelectable: "content-container--selectable", contentContainerHasCenterContent: "content-container--has-center-content", nestedContainer: "nested-container", diff --git a/packages/calcite-components/src/components/list/list.stories.ts b/packages/calcite-components/src/components/list/list.stories.ts index 00c1c921963..138720e2c21 100644 --- a/packages/calcite-components/src/components/list/list.stories.ts +++ b/packages/calcite-components/src/components/list/list.stories.ts @@ -90,6 +90,11 @@ export const simple = (args: ListStoryArgs): string => html` description="Vestibulum auctor dapibus neque. " > + `; @@ -286,6 +291,14 @@ export const startAndEndContentSlots = (): string => Halp! + + + + Some value or something and a thing. +
+ Halp! +
+
`; export const contentBottomSlots = (): string => @@ -299,6 +312,9 @@ export const contentBottomSlots = (): string => Some value or something and a thing. + + Some value or something and a thing. + `; export const contentBottomSlotsNested = (): string => diff --git a/packages/calcite-components/src/demos/list.html b/packages/calcite-components/src/demos/list.html index 92e783add62..330842570b0 100644 --- a/packages/calcite-components/src/demos/list.html +++ b/packages/calcite-components/src/demos/list.html @@ -90,7 +90,14 @@

List

--calcite-color-status-success > - + + + +