Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 125ac51

Browse filesBrowse files
Merge pull request #464 from github/fix-a11y-no-title-attribute
[Fix] Only look at semantic elements for `a11y-no-title-attribute`
2 parents 8abef65 + ee9e16d commit 125ac51
Copy full SHA for 125ac51

File tree

Expand file treeCollapse file tree

3 files changed

+11
-14
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+11
-14
lines changed

‎lib/rules/a11y-no-title-attribute.js

Copy file name to clipboardExpand all lines: lib/rules/a11y-no-title-attribute.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = {
5050
create(context) {
5151
return {
5252
JSXElement: node => {
53-
const elementType = getElementType(context, node.openingElement)
53+
const elementType = getElementType(context, node.openingElement, true)
5454
if (elementType !== `iframe` && ifSemanticElement(context, node)) {
5555
const titleProp = getPropValue(getProp(node.openingElement.attributes, `title`))
5656
if (titleProp) {

‎lib/utils/get-element-type.js

Copy file name to clipboardExpand all lines: lib/utils/get-element-type.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ If a prop determines the type, it can be specified with `props`.
77
88
For now, we only support the mapping of one prop type to an element type, rather than combinations of props.
99
*/
10-
function getElementType(context, node, ignoreMap = false) {
10+
function getElementType(context, node, lazyElementCheck = false) {
1111
const {settings} = context
1212

13+
if (lazyElementCheck) {
14+
return elementType(node)
15+
}
16+
1317
// check if the node contains a polymorphic prop
1418
const polymorphicPropName = settings?.github?.polymorphicPropName ?? 'as'
1519
const rawElement = getLiteralPropValue(getProp(node.attributes, polymorphicPropName)) ?? elementType(node)
1620

1721
// if a component configuration does not exists, return the raw element
18-
if (ignoreMap || !settings?.github?.components?.[rawElement]) return rawElement
22+
if (!settings?.github?.components?.[rawElement]) return rawElement
1923

2024
const defaultComponent = settings.github.components[rawElement]
2125

‎tests/a11y-no-title-attribute.js

Copy file name to clipboardExpand all lines: tests/a11y-no-title-attribute.js
+4-11Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,13 @@ ruleTester.run('a11y-no-title-attribute', rule, {
4040
},
4141
},
4242
},
43+
{
44+
// Note: we are only checking semantic elements. We cannot make assumptions about how a React Components is using the title prop.
45+
code: '<Link as="a" title="some title">Submit</Link>',
46+
},
4347
],
4448
invalid: [
4549
{code: '<a title="some title" href="github.com">GitHub</a>', errors: [{message: errorMessage}]},
4650
{code: '<span><button title="some title">submit</button></span>', errors: [{message: errorMessage}]},
47-
{
48-
code: '<Component as="a" title="some title">Submit</Component>',
49-
errors: [{message: errorMessage}],
50-
settings: {
51-
github: {
52-
components: {
53-
Component: 'iframe',
54-
},
55-
},
56-
},
57-
},
5851
],
5952
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.