Skip to content

Commit 5d6bf0b

Browse files
autavares-devgithub-actions[bot]
authored andcommitted
Fix truncatable-part keyboard accessibility
(cherry picked from commit 6cb4faa)
1 parent 6cd0926 commit 5d6bf0b

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/app/shared/truncatable/truncatable-part/truncatable-part.component.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
<div #content class="content dont-break-out preserve-line-breaks">
33
<ng-content></ng-content>
44
</div>
5-
<button class="btn btn-link p-0 expandButton" dsDragClick (actualClick)="toggle()">
6-
<i class="fas fa-angle-down"></i>
7-
<span class="ml-1">{{ 'item.truncatable-part.show-more' | translate }}</span>
8-
</button>
9-
<button class="btn btn-link p-0 collapseButton" dsDragClick (actualClick)="toggle()" *ngIf="expand && expandable">
10-
<i class="fas fa-angle-up"></i>
11-
<span class="ml-1">{{ 'item.truncatable-part.show-less' | translate }}</span>
5+
<button
6+
class="btn btn-link p-0 {{isExpanded ? 'collapseButton' : 'expandButton'}}"
7+
dsDragClick
8+
(actualClick)="toggle()"
9+
(keyup.Enter)="toggle()"
10+
(keyup.Space)="toggle()"
11+
role="button"
12+
[attr.aria-expanded]="isExpanded"
13+
>
14+
<i class="fas {{isExpanded ? 'fa-angle-up' : 'fa-angle-down'}}"></i>
15+
<span class="ml-1">{{ 'item.truncatable-part.show-' + (isExpanded ? 'less' : 'more') | translate }}</span>
1216
</button>
1317
</div>

src/app/shared/truncatable/truncatable-part/truncatable-part.component.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ describe('TruncatablePartComponent', () => {
7373
const a = fixture.debugElement.query(By.css('.collapseButton'));
7474
expect(a).toBeNull();
7575
});
76+
77+
it('expandButton aria-expanded should be false', () => {
78+
const btn = fixture.debugElement.query(By.css('.expandButton'));
79+
expect(btn.nativeElement.getAttribute('aria-expanded')).toEqual('false');
80+
});
7681
});
7782

7883
describe('When the item is expanded', () => {
@@ -101,6 +106,14 @@ describe('TruncatablePartComponent', () => {
101106
const a = fixture.debugElement.query(By.css('.collapseButton'));
102107
expect(a).not.toBeNull();
103108
});
109+
110+
it('collapseButton aria-expanded should be true', () => {
111+
(comp as any).setLines();
112+
(comp as any).expandable = true;
113+
fixture.detectChanges();
114+
const btn = fixture.debugElement.query(By.css('.collapseButton'));
115+
expect(btn.nativeElement.getAttribute('aria-expanded')).toEqual('true');
116+
});
104117
});
105118
});
106119

src/app/shared/truncatable/truncatable-part/truncatable-part.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ export class TruncatablePartComponent implements AfterViewChecked, OnInit, OnDes
136136
}
137137
}
138138

139+
/**
140+
* Indicates if the content is expanded, button state is 'Collapse'
141+
*/
142+
public get isExpanded() {
143+
return this.expand && this.expandable;
144+
}
145+
139146
/**
140147
* Unsubscribe from the subscription
141148
*/

0 commit comments

Comments
 (0)