Skip to content

Commit

Permalink
fix: update nested to be observable and set isNestedItem method to re…
Browse files Browse the repository at this point in the history
…adonly (microsoft#3539)

* fix: update nested to be observable and set isNestedItem method to readonly

* remove !!
  • Loading branch information
chrisdholt authored Jul 22, 2020
1 parent 4fe0dd3 commit 9e67f52
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ <h4>With items (don't render collapsed nodes)</h4>
<fast-tree-view render-collapsed-nodes="false">
<fast-tree-item>
Root item 1
<fast-divider></fast-divider>
<fast-tree-item>
Flowers
<fast-tree-item disabled>Daisy</fast-tree-item>
Expand Down Expand Up @@ -35,6 +34,7 @@ <h4>Flat tree</h4>
<fast-tree-item selected>Daisy</fast-tree-item>
<fast-tree-item>Sunflower</fast-tree-item>
<fast-tree-item>Rose</fast-tree-item>
<fast-divider></fast-divider>
<fast-tree-item>Petunia</fast-tree-item>
<fast-tree-item>Tulip</fast-tree-item>
</fast-tree-view>
Expand Down
3 changes: 2 additions & 1 deletion packages/web-components/fast-foundation/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,10 @@ export class TreeItem extends FASTElement {
// (undocumented)
handleKeyDown: (e: KeyboardEvent) => void | boolean;
// (undocumented)
isNestedItem(): null | boolean;
readonly isNestedItem: () => boolean;
// (undocumented)
items: HTMLElement[];
// @internal (undocumented)
nested: boolean;
// (undocumented)
renderCollapsedChildren: boolean;
Expand Down
15 changes: 5 additions & 10 deletions packages/web-components/fast-foundation/src/tree-item/tree-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ export class TreeItem extends FASTElement {
}

/**
* Tracks the nested state of the item
* @public
* @remarks
* HTML Attribute: nested
* @internal
*/
@attr({ mode: "boolean" })
@observable
public nested: boolean;

@observable
Expand Down Expand Up @@ -214,11 +211,9 @@ export class TreeItem extends FASTElement {
return treeChildren ? treeChildren.length : 0;
}

public isNestedItem(): null | boolean {
return (
this.parentElement && this.parentElement.getAttribute("role") === "treeitem"
);
}
public readonly isNestedItem = (): boolean => {
return isTreeItemElement(this.parentElement as Element);
};

private handleArrowLeft(): void {
if (this.expanded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class TreeView extends FASTElement {
if (this.checkForNestedItems()) {
this.slottedTreeItems.forEach(node => {
if (isTreeItemElement(node)) {
node.setAttribute("nested", "");
(node as TreeItem).nested = true;
}
});
}
Expand Down

0 comments on commit 9e67f52

Please sign in to comment.