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(list-item): an item with an empty slotted list should be openable. #8240

Merged
merged 3 commits into from
Nov 21, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import {
import { SelectionMode } from "../interfaces";
import { SelectionAppearance } from "../list/resources";
import { CSS, ICONS, SLOTS } from "./resources";
import { getDepth, getListItemChildren, updateListItemChildren } from "./utils";
import {
getDepth,
getListItemChildren,
getListItemChildLists,
updateListItemChildren,
} from "./utils";
import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale";
import {
connectMessages,
Expand Down Expand Up @@ -675,8 +680,9 @@ export class ListItem

const { parentListEl } = this;
const listItemChildren = getListItemChildren(slotEl);
const listItemChildLists = getListItemChildLists(slotEl);
updateListItemChildren(listItemChildren);
const openable = !!listItemChildren.length;
const openable = !!listItemChildren.length || !!listItemChildLists.length;

if (openable && parentListEl && !parentListEl.openable) {
parentListEl.openable = true;
Expand Down
6 changes: 6 additions & 0 deletions packages/calcite-components/src/components/list-item/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const listSelector = "calcite-list";
const listItemGroupSelector = "calcite-list-item-group";
const listItemSelector = "calcite-list-item";

export function getListItemChildLists(slotEl: HTMLSlotElement): HTMLCalciteListElement[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidebar: we should generalize these and move into dom. These are some pretty nice utils.

return Array.from(
slotEl.assignedElements({ flatten: true }).filter((el) => el.matches(listSelector))
) as HTMLCalciteListElement[];
}

export function getListItemChildren(slotEl: HTMLSlotElement): HTMLCalciteListItemElement[] {
const assignedElements = slotEl.assignedElements({ flatten: true });

Expand Down
10 changes: 10 additions & 0 deletions packages/calcite-components/src/components/list/list.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,13 @@ export const sortableNestedList_TestOnly = (): string => html`<calcite-list
<calcite-list-item label="Hi! 6" description="hello world"></calcite-list-item>
<calcite-list-item label="Hi! 7" description="hello world"></calcite-list-item>
</calcite-list>`;

export const listWithEmptyChildList_TestOnly = (): string => html`<calcite-list
drag-enabled
group="nested"
selection-mode="single"
>
<calcite-list-item open label="Hi! 4" description="hello world">
<calcite-list drag-enabled group="nested" selection-mode="single"></calcite-list>
</calcite-list-item>
</calcite-list>`;
Loading