Skip to content

Commit

Permalink
Add support for transtion{run,start,cancel} events
Browse files Browse the repository at this point in the history
  • Loading branch information
someonewithpc committed Sep 7, 2023
1 parent 953cb02 commit fc02a1b
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/react-dom-bindings/src/events/DOMEventNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export type DOMEventName =
| 'touchmove'
| 'touchstart'
// These are vendor-prefixed so you should use the exported constants instead:
// 'transitionrun' |
// 'transitionstart' |
// 'transitioncancel' |
// 'transitionend' |
| 'volumechange'
| 'waiting'
Expand All @@ -115,5 +118,12 @@ export const ANIMATION_ITERATION: DOMEventName =
getVendorPrefixedEventName('animationiteration');
export const ANIMATION_START: DOMEventName =
getVendorPrefixedEventName('animationstart');

export const TRANSITION_RUN: DOMEventName =
getVendorPrefixedEventName('transitionrun');
export const TRANSITION_START: DOMEventName =
getVendorPrefixedEventName('transitionstart');
export const TRANSITION_CANCEL: DOMEventName =
getVendorPrefixedEventName('transitioncancel');
export const TRANSITION_END: DOMEventName =
getVendorPrefixedEventName('transitionend');
7 changes: 7 additions & 0 deletions packages/react-dom-bindings/src/events/DOMEventProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
ANIMATION_END,
ANIMATION_ITERATION,
ANIMATION_START,
TRANSITION_RUN,
TRANSITION_START,
TRANSITION_CANCEL,
TRANSITION_END,
} from './DOMEventNames';

Expand Down Expand Up @@ -128,5 +131,9 @@ export function registerSimpleEvents() {
registerSimpleEvent('dblclick', 'onDoubleClick');
registerSimpleEvent('focusin', 'onFocus');
registerSimpleEvent('focusout', 'onBlur');

registerSimpleEvent(TRANSITION_RUN, 'onTransitionRun');
registerSimpleEvent(TRANSITION_START, 'onTransitionStart');
registerSimpleEvent(TRANSITION_CANCEL, 'onTransitionCancel');
registerSimpleEvent(TRANSITION_END, 'onTransitionEnd');
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const vendorPrefixes = {
animationend: makePrefixMap('Animation', 'AnimationEnd'),
animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
animationstart: makePrefixMap('Animation', 'AnimationStart'),
transitionrun: makePrefixMap('Transition', 'TransitionRun'),
transitionstart: makePrefixMap('Transition', 'TransitionStart'),
transitioncancel: makePrefixMap('Transition', 'TransitionCancel'),
transitionend: makePrefixMap('Transition', 'TransitionEnd'),
};

Expand Down
51 changes: 51 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,57 @@ describe('ReactDOMEventListener', () => {
});
});

it('onTransitionRun', () => {
testNativeBubblingEvent({
type: 'div',
reactEvent: 'onTransitionRun',
reactEventType: 'transitionrun',
nativeEvent: 'transitionrun',
dispatch(node) {
node.dispatchEvent(
new Event('transitionrun', {
bubbles: true,
cancelable: true,
}),
);
},
});
});

it('onTransitionStart', () => {
testNativeBubblingEvent({
type: 'div',
reactEvent: 'onTransitionStart',
reactEventType: 'transitionstart',
nativeEvent: 'transitionstart',
dispatch(node) {
node.dispatchEvent(
new Event('transitionstart', {
bubbles: true,
cancelable: true,
}),
);
},
});
});

it('onTransitionCancel', () => {
testNativeBubblingEvent({
type: 'div',
reactEvent: 'onTransitionCancel',
reactEventType: 'transitioncancel',
nativeEvent: 'transitioncancel',
dispatch(node) {
node.dispatchEvent(
new Event('transitioncancel', {
bubbles: true,
cancelable: true,
}),
);
},
});
});

it('onTransitionEnd', () => {
testNativeBubblingEvent({
type: 'div',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ exports[`ReactTestUtils Simulate should have locally attached media events 1`] =
"touchEnd",
"touchMove",
"touchStart",
"transitionRun",
"transitionStart",
"transitionCancel",
"transitionEnd",
"volumeChange",
"waiting",
Expand Down
3 changes: 3 additions & 0 deletions packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@ const simulatedEventTypes = [
'stalled',
'suspend',
'timeUpdate',
'transitionRun',
'transitionStart',
'transitionCancel',
'transitionEnd',
'waiting',
'mouseEnter',
Expand Down

0 comments on commit fc02a1b

Please sign in to comment.