From 812277dab6b449596288825d59184dfc1acdf370 Mon Sep 17 00:00:00 2001 From: Alfredo Granja Date: Tue, 4 Feb 2020 08:56:55 -0600 Subject: [PATCH] Fix onMouseEnter is fired on disabled buttons (#17675) --- packages/legacy-events/EventPluginHub.js | 1 + .../ReactBrowserEventEmitter-test.internal.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/legacy-events/EventPluginHub.js b/packages/legacy-events/EventPluginHub.js index 8d503640fcd1b..407946023028a 100644 --- a/packages/legacy-events/EventPluginHub.js +++ b/packages/legacy-events/EventPluginHub.js @@ -45,6 +45,7 @@ function shouldPreventMouseEvent(name, type, props) { case 'onMouseMoveCapture': case 'onMouseUp': case 'onMouseUpCapture': + case 'onMouseEnter': return !!(props.disabled && isInteractive(type)); default: return false; diff --git a/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js b/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js index b5984487936f7..57348fa556da1 100644 --- a/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js @@ -37,6 +37,7 @@ const ON_MOUSE_ENTER_KEY = 'onMouseEnter'; let GRANDPARENT; let PARENT; let CHILD; +let BUTTON; let getListener; let putListener; @@ -71,6 +72,7 @@ describe('ReactBrowserEventEmitter', () => { let GRANDPARENT_PROPS = {}; let PARENT_PROPS = {}; let CHILD_PROPS = {}; + let BUTTON_PROPS = {}; function Child(props) { return
(CHILD = c)} {...props} />; @@ -87,6 +89,7 @@ describe('ReactBrowserEventEmitter', () => {
(GRANDPARENT = c)} {...GRANDPARENT_PROPS}>
(PARENT = c)} {...PARENT_PROPS}> +
, container, @@ -110,6 +113,9 @@ describe('ReactBrowserEventEmitter', () => { case GRANDPARENT: GRANDPARENT_PROPS[eventName] = listener; break; + case BUTTON: + BUTTON_PROPS[eventName] = listener; + break; } // Rerender with new event listeners renderTree(); @@ -125,6 +131,9 @@ describe('ReactBrowserEventEmitter', () => { case GRANDPARENT: GRANDPARENT_PROPS = {}; break; + case BUTTON: + BUTTON_PROPS = {}; + break; } renderTree(); }; @@ -149,6 +158,12 @@ describe('ReactBrowserEventEmitter', () => { expect(listener).toEqual(LISTENER); }); + it('should not retrieve listeners on a disabled interactive element', () => { + putListener(BUTTON, ON_MOUSE_ENTER_KEY, recordID.bind(null, BUTTON)); + const listener = getListener(BUTTON, ON_MOUSE_ENTER_KEY); + expect(listener).toBe(null); + }); + it('should clear all handlers when asked to', () => { registerSimpleTestHandler(); deleteAllListeners(CHILD);