Skip to content

Commit

Permalink
PR: Yes/No Boolean Question - A screen reader doesn't announce the Ye…
Browse files Browse the repository at this point in the history
…s/No Options (#7716)

* work for the #7691

* work for the #7691
  • Loading branch information
dmitry-kurmanov authored Jan 23, 2024
1 parent 2a9cdae commit ebe752f
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
<label [class]="model.getItemCss()">
<input
type="checkbox"
[attr.name]="model.name" [attr.id]="model.inputId" [attr.aria-required]="model.ariaRequired" [attr.aria-label]="model.ariaLabel" [attr.aria-invalid]="model.ariaInvalid" [attr.aria-describedby]="model.ariaDescribedBy"
[attr.name]="model.name" [attr.id]="model.inputId"
[attr.role]="model.a11y_input_ariaRole"
[attr.aria-required]="model.a11y_input_ariaRequired"
[attr.aria-label]="model.a11y_input_ariaLabel"
[attr.aria-labelledby]="model.a11y_input_ariaLabelledBy"
[attr.aria-invalid]="model.a11y_input_ariaInvalid"
[attr.aria-describedby]="model.a11y_input_ariaDescribedBy"
[class]="model.cssClasses.control" [disabled]="model.isInputReadOnly" [indeterminate]="model.isIndeterminate" [value]="model.booleanValue" [(ngModel)]="model.booleanValue" />
<div [class]="model.cssClasses.sliderGhost" (click)="model.onLabelClick($event, false)">
<span [class]="model.getLabelCss(false)" [model]="model.locLabelFalse" sv-ng-string></span>
Expand Down
10 changes: 6 additions & 4 deletions packages/survey-vue3-ui/src/BooleanSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
:id="question.inputId"
:indeterminate.prop="question.isIndeterminate"
:disabled="question.isInputReadOnly"
:aria-required="question.ariaRequired"
:aria-label="question.ariaLabel"
:aria-invalid="question.ariaInvalid"
:aria-describedby="question.ariaDescribedBy"
:role="question.a11y_input_ariaRole"
:aria-required="question.a11y_input_ariaRequired"
:aria-label="question.a11y_input_ariaLabel"
:aria-labelledby="question.a11y_input_ariaLabelledBy"
:aria-invalid="question.a11y_input_ariaInvalid"
:aria-describedby="question.a11y_input_ariaDescribedBy"
/>
<div
:class="question.cssClasses.sliderGhost"
Expand Down
2 changes: 1 addition & 1 deletion src/knockout/templates/question-boolean.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<label data-bind="css: question.getItemCss()">
<input
type="checkbox"
data-bind="value: question.booleanValue, css: question.cssClasses.control, attr: {name: question.name, id: question.inputId, 'aria-required': question.ariaRequired, 'aria-label': question.ariaLabel, 'aria-invalid': question.ariaInvalid, 'aria-describedby': question.ariaDescribedBy}, checked: question.booleanValue, surveyProp: {indeterminate: question.isIndeterminate}, enable: !question.isInputReadOnly"
data-bind="value: question.booleanValue, css: question.cssClasses.control, attr: {name: question.name, id: question.inputId, 'role': question.a11y_input_ariaRole, 'aria-required': question.a11y_input_ariaRequired, 'aria-labelledby': question.a11y_input_ariaLabelledBy, 'aria-invalid': question.a11y_input_ariaInvalid, 'aria-describedby': question.a11y_input_ariaDescribedBy, 'aria-label': question.a11y_input_ariaLabel}, checked: question.booleanValue, surveyProp: {indeterminate: question.isIndeterminate}, enable: !question.isInputReadOnly"
/>
<div data-bind="css: question.cssClasses.sliderGhost, click: onFalseLabelClick">
<span data-bind="css: question.getLabelCss(false)">
Expand Down
9 changes: 9 additions & 0 deletions src/question_boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ export class QuestionBooleanModel extends Question {
protected createActionContainer(allowAdaptiveActions?: boolean): ActionContainer {
return super.createActionContainer(this.renderAs !== "checkbox");
}

//a11y
public get isNewA11yStructure(): boolean {
return true;
}
public get a11y_input_ariaRole(): string {
return "switch";
}
// EO a11y
}

Serializer.addClass(
Expand Down
10 changes: 6 additions & 4 deletions src/react/boolean.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ export class SurveyQuestionBoolean extends SurveyQuestionElementBase {
disabled={this.isDisplayMode}
checked={this.question.booleanValue || false}
onChange={this.handleOnChange}
aria-required={this.question.ariaRequired}
aria-label={this.question.ariaLabel}
aria-invalid={this.question.ariaInvalid}
aria-describedby={this.question.ariaDescribedBy}
role={this.question.a11y_input_ariaRole}
aria-required={this.question.a11y_input_ariaRequired}
aria-label={this.question.a11y_input_ariaLabel}
aria-labelledby={this.question.a11y_input_ariaLabelledBy}
aria-invalid={this.question.a11y_input_ariaInvalid}
aria-describedby={this.question.a11y_input_ariaDescribedBy}
/>
<div className={cssClasses.sliderGhost} onClick={(event) => this.handleOnLabelClick(event, false)}>
<span className={this.question.getLabelCss(false)}>
Expand Down
10 changes: 6 additions & 4 deletions src/vue/boolean-switch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
:id="question.inputId"
:indeterminate.prop="question.isIndeterminate"
:disabled="question.isInputReadOnly"
:aria-required="question.ariaRequired"
:aria-label="question.ariaLabel"
:aria-invalid="question.ariaInvalid"
:aria-describedby="question.ariaDescribedBy"
:role="question.a11y_input_ariaRole"
:aria-required="question.a11y_input_ariaRequired"
:aria-label="question.a11y_input_ariaLabel"
:aria-labelledby="question.a11y_input_ariaLabelledBy"
:aria-invalid="question.a11y_input_ariaInvalid"
:aria-describedby="question.a11y_input_ariaDescribedBy"
/>
<div
:class="question.cssClasses.sliderGhost"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="sv_qbln sv_qcbc">
<div class="sv-boolean sv-boolean--indeterminate">
<label>
<input aria-invalid="false" aria-label="Question title" aria-required="false" class="sv-visuallyvisible" id="testid0i" name="name" type="checkbox" value="">
<input class="sv-visuallyvisible" id="testid0i" name="name" type="checkbox" value="">
<span class="sv-boolean__decorator sv-item__decorator">
<svg class="sv-boolean__svg sv-item__svg">
<use xlink:href="#test-icon" class="">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="sd-selectbase">
<div class="sd-checkbox sd-checkbox--checked sd-item sd-item--checked sd-selectbase__item">
<label class="sd-selectbase__label">
<input aria-invalid="false" aria-label="Question title" aria-required="false" checked="" class="sd-checkbox__control sd-item__control sd-visuallyhidden" id="testid0i" name="name" type="checkbox" value="true">
<input checked="" class="sd-checkbox__control sd-item__control sd-visuallyhidden" id="testid0i" name="name" type="checkbox" value="true">
<span class="sd-checkbox__decorator sd-item__decorator">
<svg class="sd-checkbox__svg sd-item__svg">
<use xlink:href="#icon-v2check" class="">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="sd-selectbase">
<div class="sd-checkbox sd-checkbox--checked sd-checkbox--disabled sd-item sd-item--checked sd-item--disabled sd-selectbase__item">
<label class="sd-selectbase__label">
<input aria-invalid="false" aria-label="Question title" aria-required="false" checked="" class="sd-checkbox__control sd-item__control sd-visuallyhidden" disabled="" id="testid0i" name="name" type="checkbox" value="true">
<input checked="" class="sd-checkbox__control sd-item__control sd-visuallyhidden" disabled="" id="testid0i" name="name" type="checkbox" value="true">
<span class="sd-checkbox__decorator sd-item__decorator">
<svg class="sd-checkbox__svg sd-item__svg">
<use xlink:href="#icon-v2check" class="">
Expand Down
2 changes: 1 addition & 1 deletion tests/markup/snapshots/boolean-checkbox.snap.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="sv_qbln sv_qcbc">
<div class="sv-boolean sv-boolean--indeterminate">
<label>
<input aria-invalid="false" aria-label="Question title" aria-required="false" class="sv-visuallyvisible" id="testid0i" name="name" type="checkbox" value="">
<input class="sv-visuallyvisible" id="testid0i" name="name" type="checkbox" value="">
<span class="sv-boolean__decorator sv-item__decorator">
<span class="check">
</span>
Expand Down
2 changes: 1 addition & 1 deletion tests/markup/snapshots/boolean-v2.snap.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="sd-boolean-root sd-scrollable-container sv_qbln sv_qcbc">
<label class="sd-boolean sd-boolean--allowhover sd-boolean--indeterminate">
<input aria-invalid="false" aria-label="Question title" aria-required="false" class="sd-boolean__control sd-visuallyhidden" id="testid0i" name="name" type="checkbox" value="">
<input aria-invalid="false" aria-labelledby="testid0_ariaTitle" aria-required="false" class="sd-boolean__control sd-visuallyhidden" id="testid0i" name="name" role="switch" type="checkbox" value="">
<div class="sd-boolean__thumb-ghost">
<span class="sd-boolean__label">
<span class="sv-string-viewer">No</span>
Expand Down
2 changes: 1 addition & 1 deletion tests/markup/snapshots/boolean-value-v2.snap.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="sd-boolean-root sd-scrollable-container sv_qbln sv_qcbc">
<label class="sd-boolean sd-boolean--allowhover sd-boolean--checked">
<input aria-invalid="false" aria-label="Question title" aria-required="false" checked="" class="sd-boolean__control sd-visuallyhidden" id="testid0i" name="name" type="checkbox" value="true">
<input aria-invalid="false" aria-labelledby="testid0_ariaTitle" aria-required="false" checked="" class="sd-boolean__control sd-visuallyhidden" id="testid0i" name="name" role="switch" type="checkbox" value="true">
<div class="sd-boolean__thumb-ghost">
<span class="sd-boolean__label sd-boolean__label--false sd-checkbox__label--disabled">
<span class="sv-string-viewer">No</span>
Expand Down
2 changes: 1 addition & 1 deletion tests/markup/snapshots/boolean.snap.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="sv_qbln sv_qcbc">
<label class="sv-boolean sv-boolean--indeterminate">
<input aria-invalid="false" aria-label="Question title" aria-required="false" class="sv-visuallyhidden" id="testid0i" name="name" type="checkbox" value="">
<input aria-invalid="false" aria-labelledby="testid0_ariaTitle" aria-required="false" class="sv-visuallyhidden" id="testid0i" name="name" role="switch" type="checkbox" value="">
<div class="sv-boolean__thumb-ghost">
<span class="sv-boolean__label">
<span class="sv-string-viewer">No</span>
Expand Down

0 comments on commit ebe752f

Please sign in to comment.