Skip to content

Commit

Permalink
fix(tree-view): truncation on first render
Browse files Browse the repository at this point in the history
  • Loading branch information
cd3859 committed Feb 24, 2025
1 parent 7cab72a commit 6ecaafe
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 6ecaafe

Please sign in to comment.