MDL-70075 core: Listen for the focus and blur events again

The `blur` event does not bubble, but the `focusout` events are not
available in all supported versions of Firefox.

Rather than switching event, this patch using event capture to
effectively achieve the same result and bubble the event up through the
DOM to the delegated listener.

There should be no functional change with this patch, except to support
Firefox fully.
This commit is contained in:
Andrew Nicols
2020-11-05 09:05:38 +08:00
parent 15b4174a9f
commit f4dfe66ea8
3 changed files with 8 additions and 6 deletions
+6 -4
View File
@@ -431,16 +431,18 @@ define(['jquery', 'core/key_codes'], function($, keyCodes) {
triggerEvent(events.accessibleChange, e);
});
} else {
element.on('focusin', function(e) {
var nativeElement = element.get()[0];
// The `focus` and `blur` events do not support bubbling. Use Event Capture instead.
nativeElement.addEventListener('focus', function(e) {
$(e.target).data('initValue', e.target.value);
});
element.on('focusout', function(e) {
}, true);
nativeElement.addEventListener('blur', function(e) {
var initValue = $(e.target).data('initValue');
$(e.target).removeData('initValue');
if (e.target.value !== initValue) {
triggerEvent(events.accessibleChange, e);
}
});
}, true);
element.on('keydown', function(e) {
if ((e.which === keyCodes.enter) && e.target.value !== $(e.target).data('initValue')) {
triggerEvent(events.accessibleChange, e);