Skip to content

fix(eslint-plugin-template): any valid DOM element with role button is interactive #2488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2025

Conversation

JamesHenry
Copy link
Member

No description provided.

Copy link

nx-cloud bot commented May 31, 2025

View your CI Pipeline Execution ↗ for commit 6be30b4.

Command Status Duration Result
nx run-many -t test ✅ Succeeded 29s View ↗
nx run-many -t build ✅ Succeeded 14s View ↗
nx run-many -t e2e-suite --parallel 1 ✅ Succeeded 36s View ↗
nx run-many -t test --codeCoverage ✅ Succeeded 59s View ↗
nx run-many -t build,typecheck,check-rule-docs,... ✅ Succeeded 52s View ↗
nx-cloud record -- pnpm nx sync:check ✅ Succeeded 2s View ↗
nx-cloud record -- pnpm format-check ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-31 11:55:42 UTC

@@ -547,6 +547,9 @@ interface Options {
<a href="#" (click)="onClick()"></a>
<a [attr.href]="href" class="anchor" (click)="onClick()"></a>
<a [routerLink]="'route'" (click)="onClick()"></a>
<div role="button" (click)="doSomething()"></div>
<span role="button" (click)="doSomething()"></span>
<p role="button" (click)="doSomething()"></p>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @sandikbarr I am rushing this one a little bit to get the fix out in 19.x, I wasn't 100% if existing utils allowed me to figure this out so I put in a hardcoded check for role of button

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesHenry those elements with role button won’t behave like a button that would have built in keyboard support.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure, but for this rule, I think it makes sense not to report? It will be caught by other rules for not having a tabindex etc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix this lint issue you would have to add those event handlers and then you would process the event multiple times

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As reported here: #1996 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a fair point. Interactive-supports-focus will catch it for not being focusable, but interactive-supports-focus won’t enforce keyboard support.

@@ -44,7 +44,7 @@ function checkIsNonInteractiveRole(node: TmplAstElement): boolean {
* has a dynamic handler on it and we need to discern whether or not
* it's intention is to be interacted with on the DOM.
*/
export function isInteractiveElement(node: TmplAstElement): boolean {
export function isInherentlyInteractiveElement(node: TmplAstElement): boolean {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed for clarity, I didn't understand it at first, and I added my role=button check in here which caused a bunch of regressions in other tests

Copy link

codecov bot commented May 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.87%. Comparing base (74a854c) to head (6be30b4).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2488      +/-   ##
==========================================
+ Coverage   92.85%   92.87%   +0.02%     
==========================================
  Files         200      200              
  Lines        4169     4182      +13     
  Branches      973      977       +4     
==========================================
+ Hits         3871     3884      +13     
  Misses        229      229              
  Partials       69       69              
Flag Coverage Δ
unittest 92.87% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...template/src/rules/click-events-have-key-events.ts 100.00% <100.00%> (ø)
...n-template/src/rules/interactive-supports-focus.ts 100.00% <ø> (ø)
...template/src/utils/is-interactive-element/index.ts 100.00% <100.00%> (ø)
.../tests/rules/click-events-have-key-events/cases.ts 100.00% <ø> (ø)
...te/tests/rules/interactive-supports-focus/cases.ts 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JamesHenry JamesHenry merged commit 44a9d10 into main May 31, 2025
18 checks passed
@JamesHenry JamesHenry deleted the role-button branch May 31, 2025 12:02
igord pushed a commit to tcorral/angular-eslint that referenced this pull request Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants