Fix truncatable-part keyboard accessibility

(cherry picked from commit 6cb4faa8d3)
This commit is contained in:
autavares-dev
2024-07-22 21:20:05 -03:00
committed by github-actions[bot]
parent 6cd092671f
commit 5d6bf0bb33
3 changed files with 31 additions and 7 deletions

View File

@@ -2,12 +2,16 @@
<div #content class="content dont-break-out preserve-line-breaks">
<ng-content></ng-content>
</div>
<button class="btn btn-link p-0 expandButton" dsDragClick (actualClick)="toggle()">
<i class="fas fa-angle-down"></i>
<span class="ml-1">{{ 'item.truncatable-part.show-more' | translate }}</span>
</button>
<button class="btn btn-link p-0 collapseButton" dsDragClick (actualClick)="toggle()" *ngIf="expand && expandable">
<i class="fas fa-angle-up"></i>
<span class="ml-1">{{ 'item.truncatable-part.show-less' | translate }}</span>
<button
class="btn btn-link p-0 {{isExpanded ? 'collapseButton' : 'expandButton'}}"
dsDragClick
(actualClick)="toggle()"
(keyup.Enter)="toggle()"
(keyup.Space)="toggle()"
role="button"
[attr.aria-expanded]="isExpanded"
>
<i class="fas {{isExpanded ? 'fa-angle-up' : 'fa-angle-down'}}"></i>
<span class="ml-1">{{ 'item.truncatable-part.show-' + (isExpanded ? 'less' : 'more') | translate }}</span>
</button>
</div>

View File

@@ -73,6 +73,11 @@ describe('TruncatablePartComponent', () => {
const a = fixture.debugElement.query(By.css('.collapseButton'));
expect(a).toBeNull();
});
it('expandButton aria-expanded should be false', () => {
const btn = fixture.debugElement.query(By.css('.expandButton'));
expect(btn.nativeElement.getAttribute('aria-expanded')).toEqual('false');
});
});
describe('When the item is expanded', () => {
@@ -101,6 +106,14 @@ describe('TruncatablePartComponent', () => {
const a = fixture.debugElement.query(By.css('.collapseButton'));
expect(a).not.toBeNull();
});
it('collapseButton aria-expanded should be true', () => {
(comp as any).setLines();
(comp as any).expandable = true;
fixture.detectChanges();
const btn = fixture.debugElement.query(By.css('.collapseButton'));
expect(btn.nativeElement.getAttribute('aria-expanded')).toEqual('true');
});
});
});

View File

@@ -136,6 +136,13 @@ export class TruncatablePartComponent implements AfterViewChecked, OnInit, OnDes
}
}
/**
* Indicates if the content is expanded, button state is 'Collapse'
*/
public get isExpanded() {
return this.expand && this.expandable;
}
/**
* Unsubscribe from the subscription
*/