Skip to content

Commit 347f52e

Browse files
colfin-96Colin Finger
authored and
Colin Finger
committed
Add accessibility tests for toolbar roving tabindex functionality
1 parent cfb866c commit 347f52e

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

packages/quill/test/unit/core/quill.spec.ts

+54-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Quill', () => {
3636
});
3737

3838
test('register(path, target)', () => {
39-
class Counter {}
39+
class Counter { }
4040
Quill.register('modules/counter', Counter);
4141

4242
expect(Quill.imports).toHaveProperty('modules/counter', Counter);
@@ -59,7 +59,7 @@ describe('Quill', () => {
5959
static blotName = 'a-blot';
6060
static className = 'ql-a-blot';
6161
}
62-
class AModule {}
62+
class AModule { }
6363
Quill.register({
6464
'formats/a-blot': ABlot,
6565
'modules/a-module': AModule,
@@ -833,7 +833,7 @@ describe('Quill', () => {
833833
});
834834

835835
test('toolbar custom handler, default container', () => {
836-
const handler = () => {}; // eslint-disable-line func-style
836+
const handler = () => { }; // eslint-disable-line func-style
837837
const config = expandConfig(`#${testContainerId}`, {
838838
modules: {
839839
toolbar: {
@@ -1201,7 +1201,7 @@ describe('Quill', () => {
12011201
observer.observe(element);
12021202
// Firefox doesn't call IntersectionObserver callback unless
12031203
// there are rafs.
1204-
requestAnimationFrame(() => {});
1204+
requestAnimationFrame(() => { });
12051205
});
12061206
};
12071207

@@ -1377,4 +1377,54 @@ describe('Quill', () => {
13771377
).toEqual(0);
13781378
});
13791379
});
1380+
1381+
describe('accessibility', () => {
1382+
describe('toolbar', () => {
1383+
test('tabbing - no roving tabindex', () => {
1384+
const container = createContainer('<div></div>');
1385+
new Quill(container, {
1386+
modules: {
1387+
toolbar: [['bold', 'italic'], ['link', 'image']],
1388+
},
1389+
});
1390+
const toolbar = container?.parentElement?.querySelector('.ql-toolbar');
1391+
const buttons = toolbar?.querySelectorAll('button');
1392+
if (!buttons) {
1393+
throw new Error('No buttons found');
1394+
}
1395+
expect(buttons.length).toBe(4);
1396+
1397+
buttons.forEach((button) => {
1398+
expect(button.getAttribute('tabindex')).toBe(null);
1399+
});
1400+
});
1401+
1402+
test('tabbing - roving tabindex', () => {
1403+
const container = createContainer('<div></div>');
1404+
if (!container.parentElement) {
1405+
throw new Error('No parent element found');
1406+
}
1407+
container.parentElement.classList.add('roving-tabindex');
1408+
new Quill(container, {
1409+
modules: {
1410+
toolbar: [['bold', 'italic'], ['link', 'image']],
1411+
},
1412+
});
1413+
const toolbar = container?.parentElement?.querySelector('.ql-toolbar');
1414+
const buttons = toolbar?.querySelectorAll('button');
1415+
if (!buttons) {
1416+
throw new Error('No buttons found');
1417+
}
1418+
expect(buttons.length).toBe(4);
1419+
1420+
buttons.forEach((button, key) => {
1421+
if (key === 0) {
1422+
expect(button.getAttribute('tabindex')).toBe('0');
1423+
} else {
1424+
expect(button.getAttribute('tabindex')).toBe('-1');
1425+
}
1426+
});
1427+
});
1428+
});
1429+
});
13801430
});

0 commit comments

Comments
 (0)