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

Resume onSelect tracking after dragend #13422

Merged
merged 1 commit into from
Aug 16, 2018
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
3 changes: 3 additions & 0 deletions packages/react-dom/src/events/SelectEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import shallowEqual from 'shared/shallowEqual';
import {
TOP_BLUR,
TOP_CONTEXT_MENU,
TOP_DRAG_END,
TOP_FOCUS,
TOP_KEY_DOWN,
TOP_KEY_UP,
Expand All @@ -39,6 +40,7 @@ const eventTypes = {
dependencies: [
TOP_BLUR,
TOP_CONTEXT_MENU,
TOP_DRAG_END,
TOP_FOCUS,
TOP_KEY_DOWN,
TOP_KEY_UP,
Expand Down Expand Up @@ -200,6 +202,7 @@ const SelectEventPlugin = {
break;
case TOP_CONTEXT_MENU:
case TOP_MOUSE_UP:
case TOP_DRAG_END:
mouseDown = false;
return constructSelectEvent(nativeEvent, nativeEventTarget);
// Chrome and IE fire non-standard event when selection is changed (and
Expand Down
35 changes: 35 additions & 0 deletions packages/react-dom/src/events/__tests__/SelectEventPlugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,39 @@ describe('SelectEventPlugin', () => {
node.dispatchEvent(nativeEvent);
expect(select).toHaveBeenCalledTimes(1);
});

// Regression test for https://github.com/facebook/react/issues/11379
it('should not wait for `mouseup` after receiving `dragend`', () => {
const select = jest.fn();
const onSelect = event => {
expect(typeof event).toBe('object');
expect(event.type).toBe('select');
expect(event.target).toBe(node);
select(event.currentTarget);
};

const node = ReactDOM.render(
<input type="text" onSelect={onSelect} />,
container,
);
node.focus();

let nativeEvent = new MouseEvent('focus', {
bubbles: true,
cancelable: true,
});
node.dispatchEvent(nativeEvent);
expect(select).toHaveBeenCalledTimes(0);

nativeEvent = new MouseEvent('mousedown', {
bubbles: true,
cancelable: true,
});
node.dispatchEvent(nativeEvent);
expect(select).toHaveBeenCalledTimes(0);

nativeEvent = new MouseEvent('dragend', {bubbles: true, cancelable: true});
node.dispatchEvent(nativeEvent);
expect(select).toHaveBeenCalledTimes(1);
});
});