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"> <div #content class="content dont-break-out preserve-line-breaks">
<ng-content></ng-content> <ng-content></ng-content>
</div> </div>
<button class="btn btn-link p-0 expandButton" dsDragClick (actualClick)="toggle()"> <button
<i class="fas fa-angle-down"></i> class="btn btn-link p-0 {{isExpanded ? 'collapseButton' : 'expandButton'}}"
<span class="ml-1">{{ 'item.truncatable-part.show-more' | translate }}</span> dsDragClick
</button> (actualClick)="toggle()"
<button class="btn btn-link p-0 collapseButton" dsDragClick (actualClick)="toggle()" *ngIf="expand && expandable"> (keyup.Enter)="toggle()"
<i class="fas fa-angle-up"></i> (keyup.Space)="toggle()"
<span class="ml-1">{{ 'item.truncatable-part.show-less' | translate }}</span> 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> </button>
</div> </div>

View File

@@ -73,6 +73,11 @@ describe('TruncatablePartComponent', () => {
const a = fixture.debugElement.query(By.css('.collapseButton')); const a = fixture.debugElement.query(By.css('.collapseButton'));
expect(a).toBeNull(); 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', () => { describe('When the item is expanded', () => {
@@ -101,6 +106,14 @@ describe('TruncatablePartComponent', () => {
const a = fixture.debugElement.query(By.css('.collapseButton')); const a = fixture.debugElement.query(By.css('.collapseButton'));
expect(a).not.toBeNull(); 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 * Unsubscribe from the subscription
*/ */