From 4925ba8d0bf80a4b1d8e8645d310590bf1b40b64 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 20 Sep 2024 14:09:27 -0700 Subject: [PATCH] [Fix] handle interactive/noninteractive changes from aria-query --- __mocks__/genInteractives.js | 22 +++++++----- .../control-has-associated-label-test.js | 2 +- ...oninteractive-element-interactions-test.js | 24 ++++++------- ...active-element-to-interactive-role-test.js | 32 ++++++++--------- .../no-static-element-interactions-test.js | 34 +++++++++---------- .../src/rules/prefer-tag-over-role-test.js | 2 +- src/util/isInteractiveElement.js | 5 --- src/util/isNonInteractiveElement.js | 1 + 8 files changed, 62 insertions(+), 60 deletions(-) diff --git a/__mocks__/genInteractives.js b/__mocks__/genInteractives.js index 68b239260..70c7c877d 100644 --- a/__mocks__/genInteractives.js +++ b/__mocks__/genInteractives.js @@ -45,14 +45,14 @@ const interactiveElementsMap = { 'input[type="time"]': [{ prop: 'type', value: 'time' }], 'input[type="url"]': [{ prop: 'type', value: 'url' }], 'input[type="week"]': [{ prop: 'type', value: 'week' }], - link: [{ prop: 'href', value: '#' }], menuitem: [], option: [], select: [], + summary: [], // Whereas ARIA makes a distinction between cell and gridcell, the AXObject // treats them both as CellRole and since gridcell is interactive, we consider // cell interactive as well. - // td: [], + td: [], th: [], tr: [], textarea: [], @@ -61,25 +61,27 @@ const interactiveElementsMap = { const nonInteractiveElementsMap: {[string]: Array<{[string]: string}>} = { abbr: [], - aside: [], + address: [], article: [], + aside: [], blockquote: [], - body: [], br: [], caption: [], + code: [], dd: [], + del: [], details: [], dfn: [], dialog: [], dir: [], dl: [], dt: [], + em: [], fieldset: [], figcaption: [], figure: [], footer: [], form: [], - frame: [], h1: [], h2: [], h3: [], @@ -87,8 +89,10 @@ const nonInteractiveElementsMap: {[string]: Array<{[string]: string}>} = { h5: [], h6: [], hr: [], + html: [], iframe: [], img: [], + ins: [], label: [], legend: [], li: [], @@ -107,20 +111,22 @@ const nonInteractiveElementsMap: {[string]: Array<{[string]: string}>} = { ruby: [], 'section[aria-label]': [{ prop: 'aria-label' }], 'section[aria-labelledby]': [{ prop: 'aria-labelledby' }], + strong: [], + sub: [], + sup: [], table: [], tbody: [], - td: [], tfoot: [], thead: [], time: [], ul: [], }; -const indeterminantInteractiveElementsMap: { [key: string]: Array } = fromEntries(domElements.map((name: string) => [name, []])); +const indeterminantInteractiveElementsMap: { [key: string]: Array } = fromEntries(domElements.map((name) => [name, []])); Object.keys(interactiveElementsMap) .concat(Object.keys(nonInteractiveElementsMap)) - .forEach((name: string) => delete indeterminantInteractiveElementsMap[name]); + .forEach((name) => delete indeterminantInteractiveElementsMap[name]); const abstractRoles = roleNames.filter((role) => roles.get(role).abstract); diff --git a/__tests__/src/rules/control-has-associated-label-test.js b/__tests__/src/rules/control-has-associated-label-test.js index e175f316e..d973f2cd7 100644 --- a/__tests__/src/rules/control-has-associated-label-test.js +++ b/__tests__/src/rules/control-has-associated-label-test.js @@ -157,7 +157,6 @@ const alwaysValid = [ { code: '
' }, { code: '' }, { code: '' }, - { code: '' }, { code: '' }, { code: ' {}} />;' }, /* HTML elements with neither an interactive or non-interactive valence (static) */ { code: ' {}} />;' }, - { code: '
{}} />;' }, { code: ' {}} />;' }, { code: '
{}} />;' }, { code: '{}} />;' }, { code: ' {}} />;' }, { code: ' {}} />;' }, { code: ' {}} />;' }, - { code: ' {}} />;' }, { code: '
;' }, { code: '
;' }, { code: '
;' }, @@ -107,7 +105,6 @@ const alwaysValid = [ { code: '
void 0} {...props} />;' }, { code: '
;' }, { code: '
void 0} aria-hidden={false} />;' }, - { code: ' {}} />;' }, { code: ' {}} />;' }, { code: ' {}} />;' }, { code: ' {}} />;' }, @@ -121,11 +118,11 @@ const alwaysValid = [ `, }, + { code: ' {}} />;' }, { code: ' {}} />;' }, { code: ' {}} />;' }, { code: '
{}} />;' }, { code: '
{}} />;' }, - { code: ' {}} />;' }, { code: ' {}} />;' }, { code: '
' }, { code: '
', errors: [expectedError] }, + { code: '', errors: [expectedError] }, // Interactive Roles { code: '
', errors: [expectedError] }, { code: '
', errors: [expectedError] }, diff --git a/__tests__/src/rules/no-noninteractive-element-interactions-test.js b/__tests__/src/rules/no-noninteractive-element-interactions-test.js index c75311cd5..759fcf9a1 100644 --- a/__tests__/src/rules/no-noninteractive-element-interactions-test.js +++ b/__tests__/src/rules/no-noninteractive-element-interactions-test.js @@ -69,6 +69,7 @@ const alwaysValid = [ { code: ' void 0} href="http://x.y.z" />' }, { code: ' void 0} href="http://x.y.z" tabIndex="0" />' }, { code: ' {}} />;' }, + { code: ' {}} />;' }, { code: '