Skip to content

Commit 99a4e38

Browse files
committed
Fix onMouseEnter is fired on disabled buttons
1 parent 1b9328c commit 99a4e38

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/legacy-events/EventPluginHub.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function shouldPreventMouseEvent(name, type, props) {
4545
case 'onMouseMoveCapture':
4646
case 'onMouseUp':
4747
case 'onMouseUpCapture':
48+
case 'onMouseEnter':
4849
return !!(props.disabled && isInteractive(type));
4950
default:
5051
return false;

packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const ON_MOUSE_ENTER_KEY = 'onMouseEnter';
3737
let GRANDPARENT;
3838
let PARENT;
3939
let CHILD;
40+
let BUTTON;
4041

4142
let getListener;
4243
let putListener;
@@ -71,6 +72,7 @@ describe('ReactBrowserEventEmitter', () => {
7172
let GRANDPARENT_PROPS = {};
7273
let PARENT_PROPS = {};
7374
let CHILD_PROPS = {};
75+
let BUTTON_PROPS = {};
7476

7577
function Child(props) {
7678
return <div ref={c => (CHILD = c)} {...props} />;
@@ -87,6 +89,7 @@ describe('ReactBrowserEventEmitter', () => {
8789
<div ref={c => (GRANDPARENT = c)} {...GRANDPARENT_PROPS}>
8890
<div ref={c => (PARENT = c)} {...PARENT_PROPS}>
8991
<ChildWrapper {...CHILD_PROPS} />
92+
<button disabled ref={ c => (BUTTON = c)} {...BUTTON_PROPS}></button>
9093
</div>
9194
</div>,
9295
container,
@@ -109,6 +112,8 @@ describe('ReactBrowserEventEmitter', () => {
109112
break;
110113
case GRANDPARENT:
111114
GRANDPARENT_PROPS[eventName] = listener;
115+
case BUTTON:
116+
BUTTON_PROPS[eventName] = listener;
112117
break;
113118
}
114119
// Rerender with new event listeners
@@ -124,6 +129,8 @@ describe('ReactBrowserEventEmitter', () => {
124129
break;
125130
case GRANDPARENT:
126131
GRANDPARENT_PROPS = {};
132+
case BUTTON:
133+
BUTTON_PROPS = {};
127134
break;
128135
}
129136
renderTree();
@@ -149,6 +156,12 @@ describe('ReactBrowserEventEmitter', () => {
149156
expect(listener).toEqual(LISTENER);
150157
});
151158

159+
it('should not retrieve a listener for disabled interactive elements', () => {
160+
putListener(BUTTON, ON_MOUSE_ENTER_KEY, recordID.bind(null, BUTTON));
161+
const listener = getListener(BUTTON, ON_MOUSE_ENTER_KEY);
162+
expect(listener).toBe(null);
163+
});
164+
152165
it('should clear all handlers when asked to', () => {
153166
registerSimpleTestHandler();
154167
deleteAllListeners(CHILD);

0 commit comments

Comments
 (0)