Skip to content

Commit

Permalink
add some tests for dynamic tabbability
Browse files Browse the repository at this point in the history
  • Loading branch information
eluberoff committed Feb 3, 2025
1 parent d5097b0 commit 66f776f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/services/textarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Options.prototype.substituteTextarea = function () {
autocomplete: 'off',
autocorrect: 'off',
spellcheck: false,
'x-palm-disable-ste-all': true,
'x-palm-disable-ste-all': true
});
};

Expand Down Expand Up @@ -80,13 +80,13 @@ class Controller extends Controller_scrollHoriz {
this.wasTabbable = tabbable;

this.textarea?.setAttribute('tabindex', tabbable ? '0' : '-1');

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 {
Expand Down
23 changes: 20 additions & 3 deletions test/unit/aria.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,32 @@ suite('aria', function () {
staticMath.latex('1+\\frac{1}{x}');
var ariaHiddenChildren = $(container).find('[aria-hidden]="true"');
assert.equal(ariaHiddenChildren.length, 2, '2 aria-hidden elements');
assert.ok(
ariaHiddenChildren[1].nodeName,
'textarea',
assert.equal(
ariaHiddenChildren[0].nodeName,
'TEXTAREA',
'aria-hidden is set on static math textarea'
);
assert.ok(
ariaHiddenChildren[1].classList.contains('mq-root-block'),
'aria-hidden is set on mq-root-block'
);

staticMath.setTabbable(true);
var ariaHiddenChildren = $(container).find('[aria-hidden]="true"');
assert.equal(ariaHiddenChildren.length, 2, '2 aria-hidden elements');
assert.equal(
ariaHiddenChildren[0].nodeName,
'SPAN',
'aria-hidden is set on mathspeak span when tabbable'
);

staticMath.setTabbable(false);
var ariaHiddenChildren = $(container).find('[aria-hidden]="true"');
assert.equal(
ariaHiddenChildren[0].nodeName,
'TEXTAREA',
'aria-hidden is again set on textarea when no longer tabbable'
);
});

test('Tabbable static math aria-hidden', function () {
Expand Down
43 changes: 43 additions & 0 deletions test/unit/focusBlur.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,49 @@ suite('focusBlur', function () {
);

assert.equal($(document.activeElement).attr('tabindex'), '0');
mq.setTabbable(false);
assert.equal(
$(document.activeElement).attr('tabindex'),
'-1',
'tab index updated when setTabbable:false called'
);

mq.setTabbable(true);
assert.equal(
$(document.activeElement).attr('tabindex'),
'0',
'tab index restored when setTabbable:true called'
);

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

test('tabindex for editable math', function () {
var mq = MQ.MathField($('<span></span>').appendTo('#mock')[0], {
tabbable: false
});

mq.focus();
mq.typedText('1+1');

assertHasFocus(mq, 'math field');
assert.equal(mq.latex(), '1+1', 'latex populated');

assert.equal($(document.activeElement).attr('tabindex'), '-1');
mq.setTabbable(true);
assert.equal(
$(document.activeElement).attr('tabindex'),
'0',
'tab index updated when setTabbable:true called'
);

mq.setTabbable(false);
assert.equal(
$(document.activeElement).attr('tabindex'),
'-1',
'tab index restored when setTabbable:false called'
);

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

0 comments on commit 66f776f

Please sign in to comment.