mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Fix truncatable-part keyboard accessibility
(cherry picked from commit 6cb4faa8d3
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
6cd092671f
commit
5d6bf0bb33
@@ -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>
|
||||
|
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user