Skip to content

Commit

Permalink
Merge pull request #3238 from mi6/3171-inconsistencies-with-ictreevie…
Browse files Browse the repository at this point in the history
…w-truncation

fix(canary-web-components): truncation on first render
  • Loading branch information
ad9242 authored Feb 25, 2025
2 parents 4f35305 + 9365b0d commit 10ca79c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,16 @@ export class TreeItem {
childList: true,
});
}

componentDidUpdate(): void {
// Truncation is run here because truncateTreeItem prop gets applied on second render
// if being passed down from parent tree view
componentDidRender(): void {
this.truncateTreeItem && this.truncateTreeItemLabel(this.el);
if (this.expanded) {
this.childTreeItems.forEach((child: HTMLIcTreeItemElement) => {
child.truncateTreeItem && this.truncateTreeItemLabel(child);
});
}
}

componentDidUpdate(): void {
if (this.hasParentExpanded) {
this.childTreeItems.forEach((child: HTMLIcTreeItemElement) => {
child.truncateTreeItem && this.truncateTreeItemLabel(child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,20 @@ export class TreeView {

this.hostMutationObserver?.disconnect();
}

componentDidLoad(): void {
componentWillLoad(): void {
this.setTreeItems();

this.watchSizeHandler();
this.watchFocusInsetHandler();
this.watchThemeHandler();
this.watchTruncateTreeItemsHandler();
}

componentDidRender(): void {
this.truncateHeading && this.truncateTreeViewHeading();
}

componentDidLoad(): void {
this.addSlotChangeListener();

this.hostMutationObserver = new MutationObserver((mutationList) =>
Expand Down Expand Up @@ -295,15 +298,7 @@ export class TreeView {
};

render() {
const {
focusInset,
heading,
isLoaded,
size,
theme,
truncateHeading,
truncateTreeItems,
} = this;
const { heading, isLoaded, size, theme, truncateHeading } = this;

return (
<Host
Expand Down Expand Up @@ -338,16 +333,8 @@ export class TreeView {
</ic-typography>
</div>
)}
<div
// Hide tree items until fully loaded with props passed down from tree view - prevents FOUC
class={{
"tree-items-container-hidden":
(focusInset || size !== "medium" || truncateTreeItems) &&
!isLoaded,
}}
>
<slot></slot>
</div>

<slot></slot>
</Host>
);
}
Expand Down

0 comments on commit 10ca79c

Please sign in to comment.