From 710d57ebdd5fa249c8a6b72399e80d9759a4e9ea Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Mon, 16 Nov 2020 09:39:28 +0100 Subject: [PATCH 1/3] test: add failing test --- src/__tests__/role.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/__tests__/role.js b/src/__tests__/role.js index af0ffd5c..109d2e62 100644 --- a/src/__tests__/role.js +++ b/src/__tests__/role.js @@ -543,3 +543,8 @@ describe('configuration', () => { } }) }) + +test('should find the input using type property instead of attribute', () => { + const {getByRole} = render('') + expect(getByRole('textbox')).not.toBeNull() +}) From 686492c0b20ef2da53253d47238201f827d3e42b Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Mon, 16 Nov 2020 09:39:40 +0100 Subject: [PATCH 2/3] fix: use type property instead of selector when matching type=text input close #814 --- src/role-helpers.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/role-helpers.js b/src/role-helpers.js index 816e592e..276b308d 100644 --- a/src/role-helpers.js +++ b/src/role-helpers.js @@ -65,8 +65,8 @@ function isInaccessible(element, options = {}) { function getImplicitAriaRoles(currentNode) { // eslint bug here: // eslint-disable-next-line no-unused-vars - for (const {selector, roles} of elementRoleList) { - if (currentNode.matches(selector)) { + for (const {match, roles} of elementRoleList) { + if (match(currentNode)) { return [...roles] } } @@ -101,6 +101,31 @@ function buildElementRoleList(elementRolesMap) { return rightSpecificity - leftSpecificity } + function match(element) { + return node => { + let {attributes = []} = element + // https://github.com/testing-library/dom-testing-library/issues/814 + const typeTextIndex = attributes.findIndex( + attribute => + attribute.value && + attribute.name === 'type' && + attribute.value === 'text', + ) + if (typeTextIndex >= 0) { + // not using splice to not mutate the attributes array + attributes = [ + ...attributes.slice(0, typeTextIndex), + ...attributes.slice(typeTextIndex + 1), + ] + if (node.type !== 'text') { + return false + } + } + + return node.matches(makeElementSelector({...element, attributes})) + } + } + let result = [] // eslint bug here: @@ -109,7 +134,7 @@ function buildElementRoleList(elementRolesMap) { result = [ ...result, { - selector: makeElementSelector(element), + match: match(element), roles: Array.from(roles), specificity: getSelectorSpecificity(element), }, From 79b8b0aa77362bef6d99629045bc2b39088939e9 Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Mon, 16 Nov 2020 09:53:47 +0100 Subject: [PATCH 3/3] refactor: remove useless default --- src/role-helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/role-helpers.js b/src/role-helpers.js index 276b308d..c7d64076 100644 --- a/src/role-helpers.js +++ b/src/role-helpers.js @@ -75,7 +75,7 @@ function getImplicitAriaRoles(currentNode) { } function buildElementRoleList(elementRolesMap) { - function makeElementSelector({name, attributes = []}) { + function makeElementSelector({name, attributes}) { return `${name}${attributes .map(({name: attributeName, value, constraints = []}) => { const shouldNotExist = constraints.indexOf('undefined') !== -1