Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix onMouseEnter is fired on disabled buttons #17675

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/legacy-events/EventPluginHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ON_MOUSE_ENTER_KEY = 'onMouseEnter';
let GRANDPARENT;
let PARENT;
let CHILD;
let BUTTON;

let getListener;
let putListener;
Expand Down Expand Up @@ -71,6 +72,7 @@ describe('ReactBrowserEventEmitter', () => {
let GRANDPARENT_PROPS = {};
let PARENT_PROPS = {};
let CHILD_PROPS = {};
let BUTTON_PROPS = {};

function Child(props) {
return <div ref={c => (CHILD = c)} {...props} />;
Expand All @@ -87,6 +89,7 @@ describe('ReactBrowserEventEmitter', () => {
<div ref={c => (GRANDPARENT = c)} {...GRANDPARENT_PROPS}>
<div ref={c => (PARENT = c)} {...PARENT_PROPS}>
<ChildWrapper {...CHILD_PROPS} />
<button disabled={true} ref={c => (BUTTON = c)} {...BUTTON_PROPS} />
</div>
</div>,
container,
Expand All @@ -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();
Expand All @@ -125,6 +131,9 @@ describe('ReactBrowserEventEmitter', () => {
case GRANDPARENT:
GRANDPARENT_PROPS = {};
break;
case BUTTON:
BUTTON_PROPS = {};
break;
}
renderTree();
};
Expand All @@ -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);
Expand Down