Skip to content

Commit 0262f9a

Browse files
committed
define Transition props
1 parent 2ee02a0 commit 0262f9a

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

packages/@react-spectrum/overlays/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@react-types/overlays": "^3.9.0",
4949
"@react-types/shared": "^3.31.0",
5050
"@swc/helpers": "^0.5.0",
51+
"@types/react-transition-group": "^4.4.12",
5152
"react-transition-group": "^4.4.5"
5253
},
5354
"devDependencies": {

packages/@react-spectrum/overlays/src/OpenTransition.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import React, {JSX, JSXElementConstructor, ReactElement} from 'react';
14-
import {Transition, TransitionProps} from 'react-transition-group';
13+
import React, {ComponentProps, JSX, JSXElementConstructor, ReactElement} from 'react';
14+
import {Transition} from 'react-transition-group';
1515

1616
const OPEN_STATES = {
1717
entering: false,
1818
entered: true
1919
};
2020

21+
type TransitionProps = ComponentProps<typeof Transition<HTMLElement>>
22+
interface OpenTransitionProps extends Omit<TransitionProps, 'children'> {
23+
children: any
24+
}
25+
2126
/**
2227
* Timeout issues adding css animations to enter may be related to
2328
* https://github.com/reactjs/react-transition-group/issues/189 or
@@ -32,16 +37,16 @@ const OPEN_STATES = {
3237
*/
3338

3439
export function OpenTransition(
35-
props: TransitionProps
36-
): JSX.Element | ReactElement<any, string | JSXElementConstructor<any>>[] {
40+
props: OpenTransitionProps
41+
): JSX.Element | ReactElement<any, string | JSXElementConstructor<any>>[] {
3742
// Do not apply any transition if in chromatic.
3843
if (process.env.CHROMATIC) {
39-
return React.Children.map(props.children, child => child && React.cloneElement(child, {isOpen: props.in}));
44+
return React.Children.map(props.children, child => child && React.isValidElement(child) && React.cloneElement(child as any, {isOpen: props.in}));
4045
}
4146

4247
return (
4348
<Transition timeout={{enter: 0, exit: 350}} {...props}>
44-
{(state) => React.Children.map(props.children, child => child && React.cloneElement(child, {isOpen: !!OPEN_STATES[state]}))}
49+
{(state) => React.Children.map(props.children, child => child && React.isValidElement(child) && React.cloneElement(child as any, {isOpen: !!OPEN_STATES[state]}))}
4550
</Transition>
4651
);
4752
}

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7260,6 +7260,7 @@ __metadata:
72607260
"@react-types/overlays": "npm:^3.9.0"
72617261
"@react-types/shared": "npm:^3.31.0"
72627262
"@swc/helpers": "npm:^0.5.0"
7263+
"@types/react-transition-group": "npm:^4.4.12"
72637264
react-transition-group: "npm:^4.4.5"
72647265
peerDependencies:
72657266
"@react-spectrum/provider": ^3.0.0
@@ -10597,6 +10598,15 @@ __metadata:
1059710598
languageName: node
1059810599
linkType: hard
1059910600

10601+
"@types/react-transition-group@npm:^4.4.12":
10602+
version: 4.4.12
10603+
resolution: "@types/react-transition-group@npm:4.4.12"
10604+
peerDependencies:
10605+
"@types/react": "*"
10606+
checksum: 10c0/0441b8b47c69312c89ec0760ba477ba1a0808a10ceef8dc1c64b1013ed78517332c30f18681b0ec0b53542731f1ed015169fed1d127cc91222638ed955478ec7
10607+
languageName: node
10608+
linkType: hard
10609+
1060010610
"@types/react@npm:19.1.8":
1060110611
version: 19.1.8
1060210612
resolution: "@types/react@npm:19.1.8"

0 commit comments

Comments
 (0)