@samitouri / QOS-React / commits / d14e443d6e

Resume onSelect tracking after dragend (#13422)

Dan Abramov committed Aug 17, 2018 at 00:22 UTC d14e443d6e97f6f4ca80d2e9a80300690b71e3c4
2 files changed +38
packages/react-dom/src/events/SelectEventPlugin.js
+3
@@ -14,6 +14,7 @@ import shallowEqual from 'shared/shallowEqual';
14 import {
15 TOP_BLUR,
16 TOP_CONTEXT_MENU,
17 + TOP_DRAG_END,
18 TOP_FOCUS,
19 TOP_KEY_DOWN,
20 TOP_KEY_UP,
@@ -39,6 +40,7 @@ const eventTypes = {
40 dependencies: [
41 TOP_BLUR,
42 TOP_CONTEXT_MENU,
43 + TOP_DRAG_END,
44 TOP_FOCUS,
45 TOP_KEY_DOWN,
46 TOP_KEY_UP,
@@ -200,6 +202,7 @@ const SelectEventPlugin = {
202 break;
203 case TOP_CONTEXT_MENU:
204 case TOP_MOUSE_UP:
205 + case TOP_DRAG_END:
206 mouseDown = false;
207 return constructSelectEvent(nativeEvent, nativeEventTarget);
208 // Chrome and IE fire non-standard event when selection is changed (and
packages/react-dom/src/events/__tests__/SelectEventPlugin-test.js
+35
@@ -108,4 +108,39 @@ describe('SelectEventPlugin', () => {
108 node.dispatchEvent(nativeEvent);
109 expect(select).toHaveBeenCalledTimes(1);
110 });
111 +
112 + // Regression test for https://github.com/facebook/react/issues/11379
113 + it('should not wait for `mouseup` after receiving `dragend`', () => {
114 + const select = jest.fn();
115 + const onSelect = event => {
116 + expect(typeof event).toBe('object');
117 + expect(event.type).toBe('select');
118 + expect(event.target).toBe(node);
119 + select(event.currentTarget);
120 + };
121 +
122 + const node = ReactDOM.render(
123 + <input type="text" onSelect={onSelect} />,
124 + container,
125 + );
126 + node.focus();
127 +
128 + let nativeEvent = new MouseEvent('focus', {
129 + bubbles: true,
130 + cancelable: true,
131 + });
132 + node.dispatchEvent(nativeEvent);
133 + expect(select).toHaveBeenCalledTimes(0);
134 +
135 + nativeEvent = new MouseEvent('mousedown', {
136 + bubbles: true,
137 + cancelable: true,
138 + });
139 + node.dispatchEvent(nativeEvent);
140 + expect(select).toHaveBeenCalledTimes(0);
141 +
142 + nativeEvent = new MouseEvent('dragend', {bubbles: true, cancelable: true});
143 + node.dispatchEvent(nativeEvent);
144 + expect(select).toHaveBeenCalledTimes(1);
145 + });
146 });