Skip to content

Remove duplicate call to canElementBeDisabled within isElementOrAncestorDisabled#724

Open
kangaechigai wants to merge 1 commit into
testing-library:mainfrom
kangaechigai:minor-isElementOrAncestorDisabled-optimization
Open

Remove duplicate call to canElementBeDisabled within isElementOrAncestorDisabled#724
kangaechigai wants to merge 1 commit into
testing-library:mainfrom
kangaechigai:minor-isElementOrAncestorDisabled-optimization

Conversation

@kangaechigai

@kangaechigai kangaechigai commented May 16, 2026

Copy link
Copy Markdown

What:

Remove a duplicate call to canElementBeDisabled within isElementOrAncestorDisabled by simply checking element.hasAttribute('disabled') directly rather than calling isElementDisabled (which does the same check but only after calling canElementBeDisabled again).

Why:

The change isn't strictly necessary, but it will improve performance when the element being checked does have the disabled attribute, since it will no longer needlessly call canElementBeDisabled a second time.

Primarily motivated/catalyzed by showing that the suggestion in #653 is unnecessary.

How:

Simply replaced isElementDisabled(element) with the body of that function and then removed the duplicate canElementBeDisabled(element).

Checklist:

  • Documentation N/A
  • Tests N/A
  • Updated Type Definitions N/A
  • Ready to be merged

since `isElementDisabled(element)` is just
`canElementBeDisabled(element) && element.hasAttribute('disabled')`,
and we already know `canElementBeDisabled(element)` is true
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.

1 participant