[MNT-21469] TreeView component has events on icon only (#5637)

* change mat-icon-button with mat-button

* align icon and label

* fix aria-label undefined value

* fix translation

* simplify html structure

* test
This commit is contained in:
Cilibiu Bogdan
2020-04-24 17:08:19 +03:00
committed by GitHub
parent d0f58600bc
commit 697ce6e365
4 changed files with 23 additions and 4 deletions

View File

@@ -342,7 +342,10 @@
}
},
"ADF-TREE-VIEW": {
"MISSING-ID": "No nodeId provided!"
"MISSING-ID": "No nodeId provided!",
"ACCESSIBILITY": {
"ARIA_LABEL": "Toggle {{ name }}"
}
},
"LIBRARY": {
"DIALOG": {

View File

@@ -8,13 +8,15 @@
<mat-tree-node class="adf-tree-view-node"
id="{{treeNode.name + '-tree-child-node'}}" *matTreeNodeDef="let treeNode; when: hasChild"
matTreeNodePadding [matTreeNodePaddingIndent]="15">
<button id="{{'button-'+treeNode.name}}" (click)="onNodeClicked(treeNode.node)"
mat-icon-button [attr.aria-label]="'toggle ' + treeNode.filename" matTreeNodeToggle>
<button matTreeNodeToggle id="{{'button-'+treeNode.name}}" (click)="onNodeClicked(treeNode.node)"
mat-icon-button [attr.aria-label]="'ADF-TREE-VIEW.ACCESSIBILITY.ARIA_LABEL' | translate: {
name: treeNode.name
}">
<mat-icon class="adf-tree-view-icon">
{{treeControl.isExpanded(treeNode) ? 'folder_open' : 'folder'}}
</mat-icon>
</button>
{{treeNode.name}}
<span class="adf-tree-view-label" matTreeNodeToggle (click)="onNodeClicked(treeNode.node)">{{treeNode.name}}</span>
</mat-tree-node>
</mat-tree>
<ng-template #missingNodeId>

View File

@@ -13,5 +13,9 @@
font-size: 12px;
align-items: baseline;
}
&-tree-view-label {
cursor: pointer;
}
}
}

View File

@@ -188,6 +188,16 @@ describe('TreeViewComponent', () => {
});
});
}));
it('should show the subfolders when the label is clicked', async(() => {
const rootLabel: HTMLButtonElement = <HTMLButtonElement> element.querySelector('.adf-tree-view-label');
rootLabel.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
});
}));
});
describe('When no nodeId is given', () => {