eslint-plugin-jsx-a11y icon indicating copy to clipboard operation
eslint-plugin-jsx-a11y copied to clipboard

Support `for` attribute

Open edoardocavazza opened this issue 1 year ago • 5 comments

This PR introduces support for for attribute as equivalent for the htmlFor property.

Related issues: #894, #961

edoardocavazza avatar Apr 08 '24 09:04 edoardocavazza

This must not be done by default, since that's not how react (the original, default, and most common usage of jsx) works.

I think a global setting should be used to map htmlFor to for, and rules updated to respect that setting - that way, custom renderers can map whatever attributes they want.

ljharb avatar Apr 08 '24 16:04 ljharb

In most of the rendering engine, both for (as attribute) and htmlFor (as property) are valid. Maybe the global setting should be an array of property names to check?

edoardocavazza avatar Apr 09 '24 08:04 edoardocavazza

React's is the primary one that matters since it has almost the entirety of the usage, but it's good to design the schema so it can support all the renderers.

how about an object, which defaults to { for: ['htmlFor'], 'class': ['className'] } etc, and then you can set it to any combination you want?

ljharb avatar Apr 09 '24 15:04 ljharb

I think it would fit a lot, but I have some issues creating the test cases for the settings :(

edoardocavazza avatar Apr 12 '24 12:04 edoardocavazza

I’d prefer to reuse this PR (but now that you’ve opened a second one, please keep both open)

ljharb avatar Apr 15 '24 15:04 ljharb