diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2023-03-27 21:47:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-27 21:47:01 +0200 |
commit | 6ad3651dbfea9e9bb56e608f72b4ef2f97bd4e70 (patch) | |
tree | 029d235d71ad5817af33d0b8e2925bb6b532c47a /src/event.js | |
parent | ce60d31893deab7d3da592b5173e90b5d50e7732 (diff) | |
download | jquery-6ad3651dbfea9e9bb56e608f72b4ef2f97bd4e70.tar.gz jquery-6ad3651dbfea9e9bb56e608f72b4ef2f97bd4e70.zip |
Event: Make trigger(focus/blur/click) work with native handlers
In `leverageNative`, instead of calling `event.stopImmediatePropagation()`
which would abort both native & jQuery handlers, set the wrapper's
`isImmediatePropagationStopped` property to a function returning `true`.
Since for each element + type pair jQuery attaches only one native handler,
there is also only one wrapper jQuery event so this achieves the goal:
on the target element jQuery handlers don't fire but native ones do.
Unfortunately, this workaround doesn't work for handlers on ancestors
- since the native event is re-wrapped by a jQuery one on each level of
the propagation, the only way to stop it for jQuery was to stop it for
everyone via native `stopPropagation()`. This is not a problem for
`focus`/`blur` which don't bubble, but it does also stop `click` on
checkboxes and radios. We accept this limitation.
Fixes gh-5015
Closes gh-5228
Diffstat (limited to 'src/event.js')
-rw-r--r-- | src/event.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/event.js b/src/event.js index 95221f475..c9a397c90 100644 --- a/src/event.js +++ b/src/event.js @@ -545,8 +545,8 @@ function leverageNative( el, type, isSetup ) { } // If this is an inner synthetic event for an event with a bubbling surrogate - // (focus or blur), assume that the surrogate already propagated from triggering the - // native event and prevent that from happening again here. + // (focus or blur), assume that the surrogate already propagated from triggering + // the native event and prevent that from happening again here. // This technically gets the ordering wrong w.r.t. to `.trigger()` (in which the // bubbling surrogate propagates *after* the non-bubbling base), but that seems // less bad than duplication. @@ -565,8 +565,16 @@ function leverageNative( el, type, isSetup ) { this ) ); - // Abort handling of the native event - event.stopImmediatePropagation(); + // Abort handling of the native event by all jQuery handlers while allowing + // native handlers on the same element to run. On target, this is achieved + // by stopping immediate propagation just on the jQuery event. However, + // the native event is re-wrapped by a jQuery one on each level of the + // propagation so the only way to stop it for jQuery is to stop it for + // everyone via native `stopPropagation()`. This is not a problem for + // focus/blur which don't bubble, but it does also stop click on checkboxes + // and radios. We accept this limitation. + event.stopPropagation(); + event.isImmediatePropagationStopped = returnTrue; } } } ); |