From 87d26826787f482aece9745f73583c1d6c3d9be0 Mon Sep 17 00:00:00 2001 From: SantoJambit <53570854+SantoJambit@users.noreply.github.com> Date: Wed, 6 Oct 2021 19:44:21 +0200 Subject: [PATCH 1/7] feat(ByAltText): Always include custom elements (#1049) --- src/__tests__/queries.find.js | 1 + src/__tests__/text-matchers.js | 32 ++++++++++++++++++++++++++++++++ src/queries/alt-text.ts | 26 ++++++++++++++++---------- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/__tests__/queries.find.js b/src/__tests__/queries.find.js index 6372f957..48d79a8b 100644 --- a/src/__tests__/queries.find.js +++ b/src/__tests__/queries.find.js @@ -31,6 +31,7 @@ test('find asynchronously finds elements', async () => { test alt text +
diff --git a/src/__tests__/text-matchers.js b/src/__tests__/text-matchers.js index 145d84bf..d272f15a 100644 --- a/src/__tests__/text-matchers.js +++ b/src/__tests__/text-matchers.js @@ -34,6 +34,15 @@ cases( query: `Finding Nemo poster`, queryFn: `queryAllByAltText`, }, + 'queryAllByAltText (for amp-img)': { + dom: ` + `, + query: `Finding Nemo poster`, + queryFn: `queryAllByAltText`, + }, queryAllByPlaceholderText: { dom: ``, query: `Dwayne 'The Rock' Johnson`, @@ -93,6 +102,16 @@ cases( query: /^Finding Nemo poster$/, queryFn: `queryAllByAltText`, }, + 'queryAllByAltText (for amp-img)': { + dom: ` + `, + query: /^Finding Nemo poster$/, + queryFn: `queryAllByAltText`, + }, queryAllByPlaceholderText: { dom: ` `, @@ -198,6 +217,15 @@ cases( query: `Finding Nemo poster`, queryFn: `queryAllByAltText`, }, + 'queryAllByAltText (for amp-img)': { + dom: ` + `, + query: `Finding Nemo poster`, + queryFn: `queryAllByAltText`, + }, }, ) @@ -251,6 +279,10 @@ cases( dom: `User ${LRM}name`, queryFn: 'queryAllByAltText', }, + 'queryAllByAltText (for amp-img)': { + dom: ``, + queryFn: 'queryAllByAltText', + }, queryAllByTitle: { dom: `
`, queryFn: 'queryAllByTitle', diff --git a/src/queries/alt-text.ts b/src/queries/alt-text.ts index a7c84031..b3c83a00 100644 --- a/src/queries/alt-text.ts +++ b/src/queries/alt-text.ts @@ -1,20 +1,26 @@ -import {wrapAllByQueryWithSuggestion} from '../query-helpers' +import { + queryAllByAttribute, + wrapAllByQueryWithSuggestion, +} from '../query-helpers' import {checkContainerType} from '../helpers' -import {AllByBoundAttribute, GetErrorFunction} from '../../types' -import {matches, fuzzyMatches, makeNormalizer, buildQueries} from './all-utils' +import { + AllByBoundAttribute, + GetErrorFunction, + MatcherOptions, +} from '../../types' +import {buildQueries} from './all-utils' + +// Valid tags are img, input, area and custom elements +const VALID_TAG_REGEXP = /^(img|input|area|.+-.+)$/i const queryAllByAltText: AllByBoundAttribute = ( container, alt, - {exact = true, collapseWhitespace, trim, normalizer} = {}, + options: MatcherOptions = {}, ) => { checkContainerType(container) - const matcher = exact ? matches : fuzzyMatches - const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer}) - return Array.from( - container.querySelectorAll('img,input,area'), - ).filter(node => - matcher(node.getAttribute('alt'), node, alt, matchNormalizer), + return queryAllByAttribute('alt', container, alt, options).filter(node => + VALID_TAG_REGEXP.test(node.tagName), ) } From ca22d25ff1a478e14e6b6bdcb13039c614c98e21 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 6 Oct 2021 19:45:01 +0200 Subject: [PATCH 2/7] docs: add SantoJambit as a contributor for code (#1050) Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 1 + 2 files changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 3ba10eb3..30cec512 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1452,6 +1452,15 @@ "contributions": [ "code" ] + }, + { + "login": "SantoJambit", + "name": "SantoJambit", + "avatar_url": "https://avatars.githubusercontent.com/u/53570854?v=4", + "profile": "https://github.com/Lusito", + "contributions": [ + "code" + ] } ], "repoHost": "https://github.com" diff --git a/README.md b/README.md index e1f3699d..699843eb 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,7 @@ Thanks goes to these people ([emoji key][emojis]):
Jack Laurence

💻 +
SantoJambit

💻 From 22e157bc865ba2f889725906f59fd60ef835500d Mon Sep 17 00:00:00 2001 From: Philipp Fritsche Date: Thu, 7 Oct 2021 14:50:23 +0200 Subject: [PATCH 3/7] chore: set protocol for npm to `https` (#1051) --- .npmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmrc b/.npmrc index d2722898..1df2a6d8 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -registry=http://registry.npmjs.org/ +registry=https://registry.npmjs.org/ package-lock=false From 845b3e139ba0ef1d0d5f72dd5e881dd689ef6346 Mon Sep 17 00:00:00 2001 From: Yashu Mittal Date: Thu, 7 Oct 2021 19:23:49 +0530 Subject: [PATCH 4/7] docs: remove extra spacing in JSDOC (#1052) --- types/queries.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/queries.d.ts b/types/queries.d.ts index 0917f8e5..1ed64151 100644 --- a/types/queries.d.ts +++ b/types/queries.d.ts @@ -109,7 +109,7 @@ export interface ByRoleOptions extends MatcherOptions { */ queryFallbacks?: boolean /** - * Only considers elements with the specified accessible name. + * Only considers elements with the specified accessible name. */ name?: | RegExp From fb6f2d5a36e06646499440f9801a433b5189b0db Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 7 Oct 2021 15:54:01 +0200 Subject: [PATCH 5/7] docs: add mittalyashu as a contributor for doc (#1053) Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 1 + 2 files changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 30cec512..679954c9 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1461,6 +1461,15 @@ "contributions": [ "code" ] + }, + { + "login": "mittalyashu", + "name": "Yashu Mittal", + "avatar_url": "https://avatars.githubusercontent.com/u/29014463?v=4", + "profile": "https://github.com/mittalyashu", + "contributions": [ + "doc" + ] } ], "repoHost": "https://github.com" diff --git a/README.md b/README.md index 699843eb..f8eb543a 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,7 @@ Thanks goes to these people ([emoji key][emojis]):
Jack Laurence

💻
SantoJambit

💻 +
Yashu Mittal

📖 From 8edfad010432f6b5878ba8505a7ff26065d5f405 Mon Sep 17 00:00:00 2001 From: Philipp Fritsche Date: Wed, 13 Oct 2021 10:11:05 +0200 Subject: [PATCH 6/7] feat(ByRole): Check only elements that could be a match (#1046) Co-authored-by: eps1lon --- src/queries/role.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/queries/role.js b/src/queries/role.js index 8f08ae67..2457b6c0 100644 --- a/src/queries/role.js +++ b/src/queries/role.js @@ -1,5 +1,5 @@ import {computeAccessibleName} from 'dom-accessibility-api' -import {roles as allRoles} from 'aria-query' +import {roles as allRoles, roleElements} from 'aria-query' import { computeAriaSelected, computeAriaChecked, @@ -99,7 +99,12 @@ function queryAllByRole( return subtreeIsInaccessibleCache.get(element) } - return Array.from(container.querySelectorAll('*')) + return Array.from( + container.querySelectorAll( + // Only query elements that can be matched by the following filters + makeRoleSelector(role, exact, normalizer ? matchNormalizer : undefined), + ), + ) .filter(node => { const isRoleSpecifiedExplicitly = node.hasAttribute('role') @@ -173,6 +178,22 @@ function queryAllByRole( }) } +function makeRoleSelector(role, exact, customNormalizer) { + if (typeof role !== 'string') { + // For non-string role parameters we can not determine the implicitRoleSelectors. + return '*' + } + + const explicitRoleSelector = + exact && !customNormalizer ? `*[role~="${role}"]` : '*[role]' + + const roleRelations = roleElements.get(role) + const implicitRoleSelectors = + roleRelations && new Set(Array.from(roleRelations).map(({name}) => name)) + + return [explicitRoleSelector, ...(implicitRoleSelectors ?? [])].join(',') +} + const getMultipleError = (c, role, {name} = {}) => { let nameHint = '' if (name === undefined) { From b569a1b82aac5d400ee63309f0cba62738922a15 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 14 Oct 2021 11:29:44 +0200 Subject: [PATCH 7/7] fix(ByRole): Ensure valid query selectors in all transpilation targets (#1055) --- src/queries/role.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/queries/role.js b/src/queries/role.js index 2457b6c0..826edd43 100644 --- a/src/queries/role.js +++ b/src/queries/role.js @@ -187,11 +187,17 @@ function makeRoleSelector(role, exact, customNormalizer) { const explicitRoleSelector = exact && !customNormalizer ? `*[role~="${role}"]` : '*[role]' - const roleRelations = roleElements.get(role) - const implicitRoleSelectors = - roleRelations && new Set(Array.from(roleRelations).map(({name}) => name)) + const roleRelations = roleElements.get(role) ?? new Set() + const implicitRoleSelectors = new Set( + Array.from(roleRelations).map(({name}) => name), + ) - return [explicitRoleSelector, ...(implicitRoleSelectors ?? [])].join(',') + // Current transpilation config sometimes assumes `...` is always applied to arrays. + // `...` is equivalent to `Array.prototype.concat` for arrays. + // If you replace this code with `[explicitRoleSelector, ...implicitRoleSelectors]`, make sure every transpilation target retains the `...` in favor of `Array.prototype.concat`. + return [explicitRoleSelector] + .concat(Array.from(implicitRoleSelectors)) + .join(',') } const getMultipleError = (c, role, {name} = {}) => {