Skip to content

Commit db63f6d

Browse files
committed
fix: click dispatch does not trigger defaults
1 parent ce21316 commit db63f6d

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

packages/react-dom/src/__tests__/ReactDOMServerIntegrationUserInteraction-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe('ReactDOMServerIntegrationUserInteraction', () => {
208208
expect(e.checked).toBe(true);
209209

210210
// simulate a user clicking.
211-
e.dispatchEvent(new Event('click', {bubbles: true, cancelable: true}));
211+
e.click();
212212

213213
expect(changeCount).toBe(1);
214214
expect(e.checked).toBe(false);

packages/react-dom/src/events/__tests__/ChangeEventPlugin-test.internal.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,7 @@ describe('ChangeEventPlugin', () => {
250250
input.checked = true;
251251
// Under the hood, uncheck the box so that the click will "check" it again.
252252
setUntrackedChecked.call(input, false);
253-
input.dispatchEvent(
254-
new MouseEvent('click', {bubbles: true, cancelable: true}),
255-
);
253+
input.click();
256254
expect(input.checked).toBe(true);
257255
// We don't expect a React event because at the time of the click, the real
258256
// checked value (true) was the same as the last recorded "current" value
@@ -261,7 +259,7 @@ describe('ChangeEventPlugin', () => {
261259

262260
// However, simulating a normal click should fire a React event because the
263261
// real value (false) would have changed from the last tracked value (true).
264-
input.dispatchEvent(new Event('click', {bubbles: true, cancelable: true}));
262+
input.click();
265263
expect(called).toBe(1);
266264
});
267265

@@ -315,24 +313,18 @@ describe('ChangeEventPlugin', () => {
315313
const option2 = div.childNodes[1];
316314

317315
// Select first option.
318-
option1.dispatchEvent(
319-
new Event('click', {bubbles: true, cancelable: true}),
320-
);
316+
option1.click();
321317
expect(called1).toBe(1);
322318
expect(called2).toBe(0);
323319

324320
// Select second option.
325-
option2.dispatchEvent(
326-
new Event('click', {bubbles: true, cancelable: true}),
327-
);
321+
option2.click();
328322
expect(called1).toBe(1);
329323
expect(called2).toBe(1);
330324

331325
// Select the first option.
332326
// It should receive the React change event again.
333-
option1.dispatchEvent(
334-
new Event('click', {bubbles: true, cancelable: true}),
335-
);
327+
option1.click();
336328
expect(called1).toBe(2);
337329
expect(called2).toBe(1);
338330
});

packages/react-interactions/events/src/dom/__tests__/Input-test.internal.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,7 @@ describe('Input event responder', () => {
424424

425425
// However, simulating a normal click should fire a React event because the
426426
// real value (false) would have changed from the last tracked value (true).
427-
ref.current.dispatchEvent(
428-
new Event('click', {bubbles: true, cancelable: true}),
429-
);
427+
ref.current.click();
430428
expect(onChangeCalled).toBe(1);
431429
expect(onValueChangeCalled).toBe(1);
432430
});
@@ -534,28 +532,22 @@ describe('Input event responder', () => {
534532
const option2 = ref.current.childNodes[1];
535533

536534
// Select first option.
537-
option1.dispatchEvent(
538-
new Event('click', {bubbles: true, cancelable: true}),
539-
);
535+
option1.click();
540536
expect(onChangeCalled1).toBe(1);
541537
expect(onValueChangeCalled1).toBe(1);
542538
expect(onChangeCalled2).toBe(0);
543539
expect(onValueChangeCalled2).toBe(0);
544540

545541
// Select second option.
546-
option2.dispatchEvent(
547-
new Event('click', {bubbles: true, cancelable: true}),
548-
);
542+
option2.click();
549543
expect(onChangeCalled1).toBe(1);
550544
expect(onValueChangeCalled1).toBe(1);
551545
expect(onChangeCalled2).toBe(1);
552546
expect(onValueChangeCalled2).toBe(1);
553547

554548
// Select the first option.
555549
// It should receive the React change event again.
556-
option1.dispatchEvent(
557-
new Event('click', {bubbles: true, cancelable: true}),
558-
);
550+
option1.click();
559551
expect(onChangeCalled1).toBe(2);
560552
expect(onValueChangeCalled1).toBe(2);
561553
expect(onChangeCalled2).toBe(1);

0 commit comments

Comments
 (0)