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(canary-web-components): truncation on first render #3238

Merged
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 @@ -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
Loading