]> source.dussan.org Git - jquery.git/commit
Event: Don't break focus triggering after `.on(focus).off(focus)`
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 10 May 2021 16:59:14 +0000 (18:59 +0200)
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 10 May 2021 17:13:25 +0000 (19:13 +0200)
commitb3e4a7eb16f68586e25a1f27f7f7c5ecba013261
tree7f6b0cb83fe707febc524dc4cfc25273aa481cf0
parent752b8981f8ee410d4c2cbada18a9afa2d880263b
Event: Don't break focus triggering after `.on(focus).off(focus)`

The `_default` function in the special event settings for focus/blur has
always returned `true` since gh-4813 as the event was already being fired
from `leverageNative`. However, that only works if there's an active handler
on that element; this made a quick consecutive call:

```js
elem.on( "focus", function() {} ).off( "focus" );
```

make subsequent `.trigger( "focus" )` calls to not do any triggering.

The solution, already used in a similar `_default` method for the `click` event,
is to check for the `dataPriv` entry on the element for the focus event
(similarly for blur).

Fixes gh-4867
Closes gh-4885

(cherry picked from commit e539bac79e666bba95bba86d690b4e609dca2286)
src/event.js
test/unit/event.js