Skip to content

Commit

Permalink
Merge pull request #3900 from DSpace/backport-3212-to-dspace-8_x
Browse files Browse the repository at this point in the history
[Port dspace-8_x] Fix truncatable-part keyboard accessibility
  • Loading branch information
tdonohue authored Jan 24, 2025
2 parents 1c78674 + b584d3f commit 0c9c876
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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', () => {
Expand Down Expand Up @@ -115,6 +120,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');
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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
*/
Expand Down

0 comments on commit 0c9c876

Please sign in to comment.