Improve cancellation of events when using disabled
or aria-disabled
attributes
#2890
+9
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes and improves the
disabled
andaria-disabled
event handling that we introduced in#1265.
We wrongly assumed that we don't want to attach any event listeners if the
disabled
oraria-disabled
props were used. While in most cases this is true, and is even a no-op (the browserdoesn't call
onClick
on a<button disabled>
) it is not true in other cases.For example
<a disabled>
doesn't exist, instead we use<a aria-hidden="">
. If we now want to"disabled" the native click behaviour we have to add
onClick={e => e.preventDefault()}
.In the linked PR, we were removing the
onClick
we could have added. In this PR we make sure toalways add
e => e.preventDefault()
instead of theonXYZ
handler we or you provided. We only dothis for
onClick
,onMouseDown
,onMouseUp
,onPointerDown
,onPoiterUp
,onKeyDown
,onKeyUp
andonKeyPress
. These are typically the events that cause an actual action that we wantto prevent instead.