File tree 1 file changed +8
-8
lines changed
1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
- Children ,
3
2
type ComponentType ,
4
3
type ForwardedRef ,
5
4
forwardRef ,
5
+ isValidElement ,
6
6
type ReactElement ,
7
7
type ReactNode ,
8
8
useEffect ,
@@ -26,20 +26,20 @@ export type SelectProps = Partial<Omit<_SelectProps, 'children' | 'renderer'>> &
26
26
} > ;
27
27
28
28
function Select ( props : SelectProps , ref : ForwardedRef < SelectElement > ) : ReactElement | null {
29
- const children = Children . toArray ( props . children as ReactNode [ ] ) ;
29
+ // React.Children.toArray() doesn't allow functions, so we convert manually.
30
+ const children = Array . isArray ( props . children ) ? props . children : [ props . children ] ;
30
31
31
32
// Components with slot attribute should stay in light DOM.
32
33
const slotted = children . filter ( ( child ) => {
33
- return typeof child === 'object' && 'props' in child && child . props . slot ;
34
+ return isValidElement ( child ) && child . props . slot ;
34
35
} ) ;
35
36
36
37
// Component without slot attribute should go to the overlay.
37
- const overlayChildren = children . filter ( ( child ) => ! slotted . includes ( child ) ) ;
38
+ const overlayChildren = children . filter ( ( child ) : child is ReactNode => {
39
+ return isValidElement ( child ) && ! slotted . includes ( child ) ;
40
+ } ) ;
38
41
39
- // React.Children.toArray() doesn't allow functions, so we convert manually.
40
- const renderFn = ( Array . isArray ( props . children ) ? props . children : [ props . children ] ) . find (
41
- ( child ) => typeof child === 'function' ,
42
- ) ;
42
+ const renderFn = children . find ( ( child ) => typeof child === 'function' ) ;
43
43
44
44
const innerRef = useRef < SelectElement > ( null ) ;
45
45
const [ portals , renderer ] = useSimpleOrChildrenRenderer (
You can’t perform that action at this time.
0 commit comments