Skip to content

Commit

Permalink
respond to code review and fix tests
Browse files Browse the repository at this point in the history
tests were failing for a couple of reasons:
(1) I was setting aria-hidden to "false" instead of not having the attribute
(2) tabindex was being set as tabindex=0 instead of now, with js, setting it to tabindex="0" (equivalent, but the getter reflects the difference)

fix the former by changing the behavior and the latter by updating the test expectation
  • Loading branch information
eluberoff committed Feb 3, 2025
1 parent c32cd5e commit d5097b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class ControllerBase {
}
setAriaLabel(ariaLabel: string) {
var oldAriaLabel = this.getAriaLabel();
if (ariaLabel === oldAriaLabel) return this;
if (ariaLabel && typeof ariaLabel === 'string' && ariaLabel !== '') {
this.ariaLabel = ariaLabel;
} else if (this.editable) {
Expand Down
1 change: 0 additions & 1 deletion src/publicapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ function getInterface(v: number): MathQuill.v3.API | MathQuill.v1.API {
}

setAriaLabel(ariaLabel: string) {
if (ariaLabel === this.__controller.getAriaLabel()) return this;
this.__controller.setAriaLabel(ariaLabel);
return this;
}
Expand Down
21 changes: 19 additions & 2 deletions src/services/textarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class Controller extends Controller_scrollHoriz {
? this.options.tabbable
: this.KIND_OF_MQ !== 'StaticMath';

if (!this.options.tabbable && this.KIND_OF_MQ === 'StaticMath') {
// aria-hide noninteractive textarea element for static math
textarea.setAttribute('aria-hidden', 'true');
}
if (tabbable && this.mathspeakSpan) {
this.mathspeakSpan.setAttribute('aria-hidden', 'true');
}
this.setTabbable(tabbable);
}

Expand All @@ -73,8 +80,18 @@ class Controller extends Controller_scrollHoriz {
this.wasTabbable = tabbable;

this.textarea?.setAttribute('tabindex', tabbable ? '0' : '-1');
this.textarea?.setAttribute('aria-hidden', !this.options.tabbable && this.KIND_OF_MQ === 'StaticMath' ? 'true' : 'false');
this.mathspeakSpan?.setAttribute('aria-hidden', tabbable ? 'true' : 'false');

if (!tabbable && this.KIND_OF_MQ === 'StaticMath') {
this.textarea?.setAttribute('aria-hidden', 'true');
} else {
this.textarea?.removeAttribute('aria-hidden');
}

if (tabbable) {
this.mathspeakSpan?.setAttribute('aria-hidden', 'true');
} else {
this.mathspeakSpan?.removeAttribute('aria-hidden');
}
}

selectionChanged() {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/focusBlur.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ suite('focusBlur', function () {
'full textarea selected'
);

assert.equal($(document.activeElement).attr('tabindex'), 0);
assert.equal($(document.activeElement).attr('tabindex'), '0');

mq.blur();
assertHasFocus(mq, 'math field', 'not');
Expand Down

0 comments on commit d5097b0

Please sign in to comment.