Skip to content

Commit

Permalink
eslint: Remove jsx-a11y/label-has-associated-control override (#39736)
Browse files Browse the repository at this point in the history
`@wordpress/eslint-plugin` sets `jsx-a11y/label-has-associated-control`
to "htmlFor", while we had it overridden to "either". Turns out there
was only place that wasn't already doing "htmlFor", so let's fix that
one place and go for it.

This also removes `jsx-a11y/label-has-for` which is deprecated in favor
of `jsx-a11y/label-has-associated-control`. The former config was
equivalent to "either".
  • Loading branch information
anomiex authored Oct 10, 2024
1 parent 0aa3315 commit 89f5928
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Replace eslint:disable for `jsx-a11y/label-has-for` with `jsx-a11y/label-has-associated-control`.


Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const FormLabel: FunctionComponent< Props & LabelProps > = ( {
const hasChildren: boolean = Children.count( children ) > 0;

return (
// eslint-disable-next-line jsx-a11y/label-has-for
// eslint-disable-next-line jsx-a11y/label-has-associated-control
<label { ...labelProps } className={ clsx( className, 'form-label' ) }>
{ children }
{ hasChildren && required && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Add auto-generated id in `MockedFilterOption`. No other change to functionality.


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Gridicon } from '@automattic/jetpack-components';
import { __, sprintf } from '@wordpress/i18n';
import React from 'react';
import React, { useId } from 'react';
import TextRowPlaceHolder from './placeholder';
import './mocked-instant-search.scss';

Expand Down Expand Up @@ -62,14 +62,18 @@ export default function MockedInstantSearch() {
);
}

const MockedFilterOption = () => (
<div className="jp-mocked-instant-search__search-filter">
<label>
<input type="checkbox" disabled="disabled" />{ ' ' }
<TextRowPlaceHolder style={ { width: '30%' } } />
</label>
</div>
);
const MockedFilterOption = () => {
const id = useId();

return (
<div className="jp-mocked-instant-search__search-filter">
<label htmlFor={ id }>
<input id={ id } type="checkbox" disabled="disabled" />{ ' ' }
<TextRowPlaceHolder style={ { width: '30%' } } />
</label>
</div>
);
};

const MockedSearchResult = () => (
<div className="jp-mocked-instant-search__search-result">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @ssr-ready **/
/* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/label-has-for */
/* eslint-disable jsx-a11y/label-has-associated-control */

import React from 'react';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Replace eslint:disable for `jsx-a11y/label-has-for` with `jsx-a11y/label-has-associated-control`.


10 changes: 0 additions & 10 deletions tools/js-tools/eslintrc/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,6 @@ module.exports = {

'jsx-a11y/anchor-has-content': 'off',
'jsx-a11y/anchor-is-valid': 'off',
'jsx-a11y/label-has-for': [
'error',
{
required: {
some: [ 'nesting', 'id' ],
},
},
],
// Redundant roles are sometimes necessary for screen reader support. For instance, VoiceOver
// on Safari requires `role=list` to announce the list if the style is overwritten.
'jsx-a11y/no-redundant-roles': 'off',
Expand Down Expand Up @@ -207,8 +199,6 @@ module.exports = {
// We may want to keep these overrides. To decide later.
eqeqeq: [ 'error', 'always', { null: 'ignore' } ],
'no-unused-expressions': [ 'error', { allowShortCircuit: true, allowTernary: true } ],
// Temporarily override plugin:@wordpress/* so we can clean up failing stuff in separate PRs.
'jsx-a11y/label-has-associated-control': [ 'error', { assert: 'either' } ],
'object-shorthand': 'off',
},
};

0 comments on commit 89f5928

Please sign in to comment.