Skip to content

Commit fceb0f8

Browse files
authored
Add "auto" class to mean the built-in should run (#32761)
Stacked on #32734 In React a ViewTransition class of `"none"` doesn't just mean that it has no class but also that it has no ViewTransition name. The default (`null | undefined`) means that it has no specific class but should run with the default built-in animation. This adds this as an explicit string called `"auto"` as well. That way you can do `<ViewTransition default="foo" enter="auto">` to override the "foo" just for the "enter" trigger to be the default built-in animation. Where as if you just specified `null` it would be like not specifying enter at all which would trigger "foo".
1 parent e0c99c4 commit fceb0f8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/react-reconciler/src/ReactFiberViewTransitionComponent.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ import {getIsHydrating} from './ReactFiberHydrationContext';
2121
import {getTreeId} from './ReactFiberTreeContext';
2222

2323
export type ViewTransitionClassPerType = {
24-
[transitionType: 'default' | string]: 'none' | string,
24+
[transitionType: 'default' | string]: 'none' | 'auto' | string,
2525
};
2626

27-
export type ViewTransitionClass = 'none' | string | ViewTransitionClassPerType;
27+
export type ViewTransitionClass =
28+
| 'none'
29+
| 'auto'
30+
| string
31+
| ViewTransitionClassPerType;
2832

2933
export type ViewTransitionProps = {
3034
name?: string,
@@ -127,7 +131,10 @@ export function getViewTransitionClassName(
127131
const className: ?string = getClassNameByType(defaultClass);
128132
const eventClassName: ?string = getClassNameByType(eventClass);
129133
if (eventClassName == null) {
130-
return className;
134+
return className === 'auto' ? null : className;
135+
}
136+
if (eventClassName === 'auto') {
137+
return null;
131138
}
132139
return eventClassName;
133140
}

0 commit comments

Comments
 (0)