Skip to content

Commit

Permalink
Re-added toggle event to non-delegated events (#19465)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Jul 27, 2020
1 parent 6bb86fd commit 217ecf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/react-dom/src/__tests__/ReactDOMEventListener-test.js
Expand Up @@ -542,20 +542,23 @@ describe('ReactDOMEventListener', () => {
const onScroll = jest.fn();
const onCancel = jest.fn();
const onClose = jest.fn();
const onToggle = jest.fn();
document.body.appendChild(container);
try {
ReactDOM.render(
<div
onPlay={onPlay}
onScroll={onScroll}
onCancel={onCancel}
onClose={onClose}>
onClose={onClose}
onToggle={onToggle}>
<div
ref={ref}
onPlay={onPlay}
onScroll={onScroll}
onCancel={onCancel}
onClose={onClose}
onToggle={onToggle}
/>
</div>,
container,
Expand All @@ -580,12 +583,18 @@ describe('ReactDOMEventListener', () => {
bubbles: false,
}),
);
ref.current.dispatchEvent(
new Event('toggle', {
bubbles: false,
}),
);
// Regression test: ensure we still emulate bubbling with non-bubbling
// media
expect(onPlay).toHaveBeenCalledTimes(2);
expect(onScroll).toHaveBeenCalledTimes(2);
expect(onCancel).toHaveBeenCalledTimes(2);
expect(onClose).toHaveBeenCalledTimes(2);
expect(onToggle).toHaveBeenCalledTimes(2);
} finally {
document.body.removeChild(container);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/react-dom/src/events/DOMPluginEventSystem.js
Expand Up @@ -68,6 +68,7 @@ import {
TOP_PLAYING,
TOP_CLICK,
TOP_SELECTION_CHANGE,
TOP_TOGGLE,
getRawEventName,
} from './DOMTopLevelEventTypes';
import {
Expand Down Expand Up @@ -239,11 +240,12 @@ export const mediaEventTypes = [
// set them on the actual target element itself. This is primarily
// because these events do not consistently bubble in the DOM.
export const nonDelegatedEvents: Set<DOMTopLevelEventType> = new Set([
TOP_SCROLL,
TOP_LOAD,
TOP_CANCEL,
TOP_CLOSE,
TOP_INVALID,
TOP_LOAD,
TOP_SCROLL,
TOP_TOGGLE,
// In order to reduce bytes, we insert the above array of media events
// into this Set. Note: the "error" event isn't an exclusive media event,
// and can occur on other elements too. Rather than duplicate that event,
Expand Down

0 comments on commit 217ecf5

Please sign in to comment.