Skip to content

Commit

Permalink
Refactor arialabel parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
VirmasaloA committed Sep 17, 2024
1 parent 7c8a970 commit 02c4fe4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@
<button
tabindex="0"
class="pointer section-box-title arrow border-none background-none"
[attr.aria-label]="
(expanded ? ('i18n_collapse' | translate) : ('i18n_expand' | translate)) +
' ' +
('i18n_question' | translate) +
' ' +
questionTitle
"
[attr.aria-label]="parseAriaLabel(expanded ? 'i18n_collapse' : 'i18n_expand')"
[attr.aria-expanded]="expanded"
(click)="expanded = !expanded"
(keydown.enter)="expanded = !expanded"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { NgClass, SlicePipe, UpperCasePipe } from '@angular/common';
import type { AfterViewInit } from '@angular/core';
import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import type { EssayAnswer } from 'src/app/exam/exam.model';
import type { Examination, ExaminationQuestion } from 'src/app/examination/examination.model';
import { ExaminationService } from 'src/app/examination/examination.service';
Expand Down Expand Up @@ -62,6 +62,7 @@ export class ExaminationQuestionComponent implements OnInit, AfterViewInit {
private cdr: ChangeDetectorRef,
private Examination: ExaminationService,
private Attachment: AttachmentService,
private translate: TranslateService,
) {}

ngOnInit() {
Expand Down Expand Up @@ -90,6 +91,16 @@ export class ExaminationQuestionComponent implements OnInit, AfterViewInit {
return result;
}

parseAriaLabel(expanded: string): string {
return (
this.translate?.instant(expanded) +
' ' +
this.translate?.instant('i18n_question') +
' ' +
this.questionTitle
);
}

ngAfterViewInit() {
this.cdr.detectChanges();
}
Expand Down

0 comments on commit 02c4fe4

Please sign in to comment.