From 068608b22a1ee03b2d43f37e5736c4745ac50eb8 Mon Sep 17 00:00:00 2001 From: LB Date: Wed, 23 Oct 2024 11:41:12 +1000 Subject: [PATCH] [New] `interactive-supports-focus`: add basic suggestions Add basic support for ESlint rule suggestions for the `interactive-supports-focus` for tabIndex values when elements are interactive but do not have implicit focusable browser behaviour. These are intentionally not auto-fix but simply optional suggestions to help developers resolve their issue. Fixes #952 See also #951 --- README.md | 83 ++++++++++--------- .../rules/interactive-supports-focus-test.js | 17 +++- docs/rules/interactive-supports-focus.md | 2 + src/rules/interactive-supports-focus.js | 27 ++++++ 4 files changed, 87 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 44cb16ea7..494a57841 100644 --- a/README.md +++ b/README.md @@ -233,49 +233,50 @@ To restrict polymorphic linting to specified components, additionally set `polym 🚫 Configurations disabled in.\ β˜‘οΈ Set in the `recommended` configuration.\ πŸ”’ Set in the `strict` configuration.\ +πŸ’‘ Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\ ❌ Deprecated. -| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  | Description | πŸ’Ό | 🚫 | ❌ | -| :----------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------- | :---- | :---- | :- | -| [accessible-emoji](docs/rules/accessible-emoji.md) | Enforce emojis are wrapped in `` and provide screen reader access. | | | ❌ | -| [alt-text](docs/rules/alt-text.md) | Enforce all elements that require alternative text have meaningful information to relay back to end user. | β˜‘οΈ πŸ”’ | | | -| [anchor-ambiguous-text](docs/rules/anchor-ambiguous-text.md) | Enforce `` text to not exactly match "click here", "here", "link", or "a link". | | β˜‘οΈ | | -| [anchor-has-content](docs/rules/anchor-has-content.md) | Enforce all anchors to contain accessible content. | β˜‘οΈ πŸ”’ | | | -| [anchor-is-valid](docs/rules/anchor-is-valid.md) | Enforce all anchors are valid, navigable elements. | β˜‘οΈ πŸ”’ | | | -| [aria-activedescendant-has-tabindex](docs/rules/aria-activedescendant-has-tabindex.md) | Enforce elements with aria-activedescendant are tabbable. | β˜‘οΈ πŸ”’ | | | -| [aria-props](docs/rules/aria-props.md) | Enforce all `aria-*` props are valid. | β˜‘οΈ πŸ”’ | | | -| [aria-proptypes](docs/rules/aria-proptypes.md) | Enforce ARIA state and property values are valid. | β˜‘οΈ πŸ”’ | | | -| [aria-role](docs/rules/aria-role.md) | Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role. | β˜‘οΈ πŸ”’ | | | -| [aria-unsupported-elements](docs/rules/aria-unsupported-elements.md) | Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes. | β˜‘οΈ πŸ”’ | | | -| [autocomplete-valid](docs/rules/autocomplete-valid.md) | Enforce that autocomplete attributes are used correctly. | β˜‘οΈ πŸ”’ | | | -| [click-events-have-key-events](docs/rules/click-events-have-key-events.md) | Enforce a clickable non-interactive element has at least one keyboard event listener. | β˜‘οΈ πŸ”’ | | | -| [control-has-associated-label](docs/rules/control-has-associated-label.md) | Enforce that a control (an interactive element) has a text label. | | β˜‘οΈ πŸ”’ | | -| [heading-has-content](docs/rules/heading-has-content.md) | Enforce heading (`h1`, `h2`, etc) elements contain accessible content. | β˜‘οΈ πŸ”’ | | | -| [html-has-lang](docs/rules/html-has-lang.md) | Enforce `` element has `lang` prop. | β˜‘οΈ πŸ”’ | | | -| [iframe-has-title](docs/rules/iframe-has-title.md) | Enforce iframe elements have a title attribute. | β˜‘οΈ πŸ”’ | | | -| [img-redundant-alt](docs/rules/img-redundant-alt.md) | Enforce `` alt prop does not contain the word "image", "picture", or "photo". | β˜‘οΈ πŸ”’ | | | -| [interactive-supports-focus](docs/rules/interactive-supports-focus.md) | Enforce that elements with interactive handlers like `onClick` must be focusable. | β˜‘οΈ πŸ”’ | | | -| [label-has-associated-control](docs/rules/label-has-associated-control.md) | Enforce that a `label` tag has a text label and an associated control. | β˜‘οΈ πŸ”’ | | | -| [label-has-for](docs/rules/label-has-for.md) | Enforce that `
`) that have click handlers use the role attribute. | β˜‘οΈ πŸ”’ | | | -| [prefer-tag-over-role](docs/rules/prefer-tag-over-role.md) | Enforces using semantic DOM elements over the ARIA `role` property. | | | | -| [role-has-required-aria-props](docs/rules/role-has-required-aria-props.md) | Enforce that elements with ARIA roles must have all required attributes for that role. | β˜‘οΈ πŸ”’ | | | -| [role-supports-aria-props](docs/rules/role-supports-aria-props.md) | Enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`. | β˜‘οΈ πŸ”’ | | | -| [scope](docs/rules/scope.md) | Enforce `scope` prop is only used on `` elements. | β˜‘οΈ πŸ”’ | | | -| [tabindex-no-positive](docs/rules/tabindex-no-positive.md) | Enforce `tabIndex` value is not greater than zero. | β˜‘οΈ πŸ”’ | | | +| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  | Description | πŸ’Ό | 🚫 | πŸ’‘ | ❌ | +| :----------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------- | :---- | :---- | :- | :- | +| [accessible-emoji](docs/rules/accessible-emoji.md) | Enforce emojis are wrapped in `` and provide screen reader access. | | | | ❌ | +| [alt-text](docs/rules/alt-text.md) | Enforce all elements that require alternative text have meaningful information to relay back to end user. | β˜‘οΈ πŸ”’ | | | | +| [anchor-ambiguous-text](docs/rules/anchor-ambiguous-text.md) | Enforce `` text to not exactly match "click here", "here", "link", or "a link". | | β˜‘οΈ | | | +| [anchor-has-content](docs/rules/anchor-has-content.md) | Enforce all anchors to contain accessible content. | β˜‘οΈ πŸ”’ | | | | +| [anchor-is-valid](docs/rules/anchor-is-valid.md) | Enforce all anchors are valid, navigable elements. | β˜‘οΈ πŸ”’ | | | | +| [aria-activedescendant-has-tabindex](docs/rules/aria-activedescendant-has-tabindex.md) | Enforce elements with aria-activedescendant are tabbable. | β˜‘οΈ πŸ”’ | | | | +| [aria-props](docs/rules/aria-props.md) | Enforce all `aria-*` props are valid. | β˜‘οΈ πŸ”’ | | | | +| [aria-proptypes](docs/rules/aria-proptypes.md) | Enforce ARIA state and property values are valid. | β˜‘οΈ πŸ”’ | | | | +| [aria-role](docs/rules/aria-role.md) | Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role. | β˜‘οΈ πŸ”’ | | | | +| [aria-unsupported-elements](docs/rules/aria-unsupported-elements.md) | Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes. | β˜‘οΈ πŸ”’ | | | | +| [autocomplete-valid](docs/rules/autocomplete-valid.md) | Enforce that autocomplete attributes are used correctly. | β˜‘οΈ πŸ”’ | | | | +| [click-events-have-key-events](docs/rules/click-events-have-key-events.md) | Enforce a clickable non-interactive element has at least one keyboard event listener. | β˜‘οΈ πŸ”’ | | | | +| [control-has-associated-label](docs/rules/control-has-associated-label.md) | Enforce that a control (an interactive element) has a text label. | | β˜‘οΈ πŸ”’ | | | +| [heading-has-content](docs/rules/heading-has-content.md) | Enforce heading (`h1`, `h2`, etc) elements contain accessible content. | β˜‘οΈ πŸ”’ | | | | +| [html-has-lang](docs/rules/html-has-lang.md) | Enforce `` element has `lang` prop. | β˜‘οΈ πŸ”’ | | | | +| [iframe-has-title](docs/rules/iframe-has-title.md) | Enforce iframe elements have a title attribute. | β˜‘οΈ πŸ”’ | | | | +| [img-redundant-alt](docs/rules/img-redundant-alt.md) | Enforce `` alt prop does not contain the word "image", "picture", or "photo". | β˜‘οΈ πŸ”’ | | | | +| [interactive-supports-focus](docs/rules/interactive-supports-focus.md) | Enforce that elements with interactive handlers like `onClick` must be focusable. | β˜‘οΈ πŸ”’ | | πŸ’‘ | | +| [label-has-associated-control](docs/rules/label-has-associated-control.md) | Enforce that a `label` tag has a text label and an associated control. | β˜‘οΈ πŸ”’ | | | | +| [label-has-for](docs/rules/label-has-for.md) | Enforce that `