-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/2.0' into ui-improvements
- Loading branch information
Showing
2 changed files
with
31 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
import type { ItemChildWrapperElement } from '../types/Elements'; | ||
import { DefaultListCssClasses } from '../ListRenderer'; | ||
import type { ItemChildWrapperElement, ItemElement } from '../types/Elements'; | ||
import { getChildItems } from './getChildItems'; | ||
import { getItemChildWrapper } from './getItemChildWrapper'; | ||
|
||
/** | ||
* Method that will remove passed child wrapper if it has no child items | ||
* @param childWrapper - childWrapper to be removed if it is empty | ||
* @param element - child wrapper or actual item, from where we get child wrapper | ||
*/ | ||
export function removeChildWrapperIfEmpty(childWrapper: ItemChildWrapperElement): void { | ||
// eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents | ||
export function removeChildWrapperIfEmpty(element: ItemChildWrapperElement | ItemElement): void { | ||
let itemChildWrapper: HTMLElement | null = element; | ||
|
||
/** | ||
* If passed element is list item than get item's child wrapper | ||
*/ | ||
if (element.classList.contains(DefaultListCssClasses.item)) { | ||
itemChildWrapper = getItemChildWrapper(element); | ||
} | ||
|
||
if (itemChildWrapper === null) { | ||
return; | ||
} | ||
|
||
/** | ||
* Check that there is at least one item | ||
*/ | ||
if (getChildItems(childWrapper).length === 0) { | ||
childWrapper.remove(); | ||
if (getChildItems(itemChildWrapper).length === 0) { | ||
itemChildWrapper.remove(); | ||
} | ||
} |