diff --git a/.all-contributorsrc b/.all-contributorsrc index bc6ef6b4..e0f082df 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1553,6 +1553,15 @@ "contributions": [ "code" ] + }, + { + "login": "kalmi", + "name": "Tarnay Kálmán", + "avatar_url": "https://avatars.githubusercontent.com/u/54426?v=4", + "profile": "https://github.com/kalmi", + "contributions": [ + "code" + ] } ], "repoHost": "https://github.com/" diff --git a/README.md b/README.md index 377ff7d5..9b814514 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,7 @@ Thanks goes to these people ([emoji key][emojis]):
Robin Drexler

💻
Omer Dolev

💻
Lirlev48

💻 +
Tarnay Kálmán

💻 diff --git a/src/role-helpers.js b/src/role-helpers.js index 0b494da5..500bcdd2 100644 --- a/src/role-helpers.js +++ b/src/role-helpers.js @@ -105,27 +105,32 @@ function buildElementRoleList(elementRolesMap) { } function match(element) { + 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), + ] + } + + const selector = makeElementSelector({...element, attributes}) + 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 - } + if (typeTextIndex >= 0 && node.type !== 'text') { + return false } - return node.matches(makeElementSelector({...element, attributes})) + return node.matches(selector) } }