Skip to content

Commit

Permalink
Do not look up as prop
Browse files Browse the repository at this point in the history
  • Loading branch information
kendallgassner committed Jul 17, 2023
1 parent 8abef65 commit b05b0cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rules/a11y-no-title-attribute.js
Expand Up @@ -50,7 +50,7 @@ module.exports = {
create(context) {
return {
JSXElement: node => {
const elementType = getElementType(context, node.openingElement)
const elementType = getElementType(context, node.openingElement, true)
if (elementType !== `iframe` && ifSemanticElement(context, node)) {
const titleProp = getPropValue(getProp(node.openingElement.attributes, `title`))
if (titleProp) {
Expand Down
8 changes: 6 additions & 2 deletions lib/utils/get-element-type.js
Expand Up @@ -7,15 +7,19 @@ If a prop determines the type, it can be specified with `props`.
For now, we only support the mapping of one prop type to an element type, rather than combinations of props.
*/
function getElementType(context, node, ignoreMap = false) {
function getElementType(context, node, lazyElementCheck = false) {
const {settings} = context

if (lazyElementCheck) {
return elementType(node)
}

// check if the node contains a polymorphic prop
const polymorphicPropName = settings?.github?.polymorphicPropName ?? 'as'
const rawElement = getLiteralPropValue(getProp(node.attributes, polymorphicPropName)) ?? elementType(node)

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

const defaultComponent = settings.github.components[rawElement]

Expand Down

0 comments on commit b05b0cb

Please sign in to comment.