Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSCEXAM-1163 Fix examination question hide button accessibility #1151

Merged
merged 9 commits into from
Oct 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ <h2 class="participation-heading">
>
<span [hidden]="showEvaluation">{{ 'i18n_comments_open' | translate }}</span>
<span [hidden]="!showEvaluation">{{ 'i18n_comments_hide' | translate }}</span>
<i [hidden]="showEvaluation" class="bi bi-chevron-right ms-2" alt="hide evaluation"></i>
<i [hidden]="!showEvaluation" class="bi bi-chevron-down ms-2" alt="show evaluation"></i>
<i [hidden]="showEvaluation" class="bi bi-chevron-right ms-2" alt=""></i>
<i [hidden]="!showEvaluation" class="bi bi-chevron-down ms-2" alt=""></i>
</button>
</div>
</div>
Expand Down
12 changes: 2 additions & 10 deletions ui/src/app/exam/editor/sections/section-question.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,8 @@
>
<span [hidden]="sectionQuestion.expanded">{{ 'i18n_show_more' | translate }}</span>
<span [hidden]="!sectionQuestion.expanded">{{ 'i18n_hide' | translate }}</span>
<i
[hidden]="sectionQuestion.expanded"
class="bi bi-chevron-right ms-2"
alt="hide evaluation"
></i>
<i
[hidden]="!sectionQuestion.expanded"
class="bi bi-chevron-down ms-2"
alt="show evaluation"
></i>
<i [hidden]="sectionQuestion.expanded" class="bi bi-chevron-right ms-2" alt=""></i>
<i [hidden]="!sectionQuestion.expanded" class="bi bi-chevron-down ms-2" alt=""></i>
</button>
}
</div>
Expand Down
27 changes: 14 additions & 13 deletions ui/src/app/examination/question/examination-question.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,21 @@
</div>
}
</div>
<!-- Expand button -->
<div class="col-auto order-2">
<button
tabindex="0"
class="pointer section-box-title arrow border-none background-none"
[attr.aria-label]="parseAriaLabel(expanded ? 'i18n_collapse' : 'i18n_expand')"
[attr.aria-expanded]="expanded"
(click)="expanded = !expanded"
(keydown.enter)="expanded = !expanded"
>
<i [ngClass]="expanded ? 'bi-chevron-down' : 'bi-chevron-right'"></i>
</button>
</div>
<!-- question text -->
<div class="col mt-3">
<div class="col mt-3 order-1">
@if (sq.question.type !== 'ClozeTestQuestion') {
@if (expanded) {
<div class="section-box-title" [xmMathJax]="sq.question.question"></div>
Expand All @@ -38,18 +51,6 @@
</div>
}
</div>
<!-- Expand button -->
<div class="col-auto">
<div
tabindex="0"
class="pointer section-box-title arrow"
[attr.aria-label]="expanded ? ('i18n_collapse' | translate) : ('i18n_expand' | translate)"
(click)="expanded = !expanded"
(keydown.enter)="expanded = !expanded"
>
<i [ngClass]="expanded ? 'bi-chevron-down' : 'bi-chevron-right'"></i>
</div>
</div>
</div>
<!-- instruction -->
@if (sq.answerInstructions && expanded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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 { Examination, ExaminationQuestion } from 'src/app/examination/examination.model';
import { ExaminationService } from 'src/app/examination/examination.service';
import { EssayAnswer } from 'src/app/question/question.model';
Expand Down Expand Up @@ -52,6 +52,7 @@ export class ExaminationQuestionComponent implements OnInit, AfterViewInit {
private cdr: ChangeDetectorRef,
private Examination: ExaminationService,
private Attachment: AttachmentService,
private translate: TranslateService,
) {}

ngOnInit() {
Expand All @@ -61,6 +62,27 @@ export class ExaminationQuestionComponent implements OnInit, AfterViewInit {
const { answer } = this.sq.clozeTestAnswer;
this.clozeAnswer = JSON.parse(answer);
}
this.questionTitle = this.removeParagraphTags(this.sq.question.question);
lupari marked this conversation as resolved.
Show resolved Hide resolved
}

removeParagraphTags(input: string): string {
const openTag = '<p>';
const closeTag = '</p>';
let result = input;

while (result.includes(openTag)) {
result = result.replace(openTag, '');
}

while (result.includes(closeTag)) {
result = result.replace(closeTag, '');
}

return result;
}

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

ngAfterViewInit() {
Expand Down