@@ -37,6 +37,14 @@ const childrenValid = (children: ReactNode, childRef: ForwardedRef<HTMLElement>)
37
37
valid = false
38
38
}
39
39
40
+ if (
41
+ valid &&
42
+ ( Children . toArray ( children ) [ 0 ] as any ) . type . toString ( ) === Symbol ( 'react.fragment' ) . toString ( )
43
+ ) {
44
+ log ( 'ReactFragmentRef' , { children } )
45
+ valid = false
46
+ }
47
+
40
48
if ( ! childRef ) {
41
49
log ( 'ReactMissingRef' )
42
50
valid = false
@@ -324,9 +332,9 @@ export const Indicate = forwardRef<HTMLElement, Props & ReactHTMLElementProperti
324
332
} ,
325
333
childRef
326
334
) => {
327
- const outerWrapperRef = useRef < HTMLDivElement > ( null )
328
- const elementRef = useRef < HTMLElement > ( null )
329
- const innerWrapperRef = useRef < HTMLDivElement & HTMLTableElement > ( null )
335
+ const outerWrapperRef = useRef < HTMLDivElement > ( )
336
+ const elementRef = useRef < HTMLElement & HTMLDivElement > ( )
337
+ const innerWrapperRef = useRef < HTMLDivElement & HTMLTableElement > ( )
330
338
const indicatorsRef = useRef < HTMLSpanElement [ ] > ( [ ] )
331
339
const isInline = getInline ( as , style && style . display )
332
340
@@ -398,7 +406,6 @@ export const Indicate = forwardRef<HTMLElement, Props & ReactHTMLElementProperti
398
406
399
407
const observe = useCallback ( ( element : HTMLElement ) => {
400
408
const observer = new IntersectionObserver ( handleObservation , {
401
- // TODO innerWrapper if table
402
409
root : element ,
403
410
// Only parts of element inside the root element are counted.
404
411
rootMargin : '0px' ,
@@ -415,36 +422,54 @@ export const Indicate = forwardRef<HTMLElement, Props & ReactHTMLElementProperti
415
422
} , [ ] )
416
423
417
424
useEffect ( ( ) => {
418
- // const outerWrapper = outerWrapperRef.current
419
425
const element = elementRef ?. current ?? ( childRef as MutableRefObject < HTMLElement > ) ?. current
420
- // const innerWrapper = innerWrapperRef?.current
421
-
422
426
const disconnectObserver = observe ( element )
423
-
424
427
return disconnectObserver
425
428
} , [ ] )
426
429
427
430
if ( childAsElement && childrenValid ( children , childRef ) ) {
428
- // cloneElement necessary to add styles, React elements immutable.
431
+ const innerChildrenModifiable = Children . toArray ( ( children as any ) . props . children )
432
+
433
+ innerChildrenModifiable . push (
434
+ < Observers key = "observers" observersRef = { observersRef } theme = { theme } />
435
+ )
436
+
437
+ // cloneElement necessary to add styles and observers, React elements immutable.
429
438
content = cloneElement ( children as ReactElement , {
430
439
...props ,
440
+ className,
441
+ children : createElement (
442
+ 'div' ,
443
+ {
444
+ style : {
445
+ // Transferring styles from child to inner wrapper.
446
+ ...( children as any ) . props . style ,
447
+ display : 'inline-flex' ,
448
+ position : 'relative' ,
449
+ verticalAlign : 'top' ,
450
+ ...innerStyle ,
451
+ ...theme . innerWrapper ,
452
+ } ,
453
+ ref : innerWrapperRef ,
454
+ ...innerWrapperProps ,
455
+ } ,
456
+ innerChildrenModifiable
457
+ ) ,
431
458
style : {
459
+ position : 'relative' ,
432
460
overflow : 'auto' ,
461
+ verticalAlign : 'top' ,
433
462
...( hideScrollbar && {
434
463
msOverflowStyle : 'none' ,
435
464
scrollbarWidth : 'none' ,
436
465
} ) ,
437
466
...style ,
438
467
...theme . element ,
439
- // ...options?.inlineStyles?.element,
440
- // ...elementProps?.style,
441
- // ...(!(childRef as MutableRefObject<HTMLElement>)?.current && options?.inlineStyles?.innerWrapper),
442
468
} ,
443
469
} )
444
470
} else if ( as === 'table' ) {
445
471
content = (
446
472
< div
447
- // @ts -ignore
448
473
ref = { elementRef }
449
474
style = { {
450
475
position : 'relative' ,
@@ -454,13 +479,13 @@ export const Indicate = forwardRef<HTMLElement, Props & ReactHTMLElementProperti
454
479
...theme . element ,
455
480
} }
456
481
>
457
- { /* @ts -ignore */ }
458
482
< table
459
483
ref = { innerWrapperRef }
460
484
style = { {
461
485
display : 'inline-block' ,
462
486
position : 'relative' ,
463
487
verticalAlign : 'top' ,
488
+ ...innerStyle ,
464
489
...theme . innerWrapper ,
465
490
} }
466
491
>
@@ -472,7 +497,6 @@ export const Indicate = forwardRef<HTMLElement, Props & ReactHTMLElementProperti
472
497
} else if ( isInline ) {
473
498
content = (
474
499
< div
475
- // @ts -ignore
476
500
ref = { elementRef }
477
501
style = { {
478
502
...style ,
@@ -490,6 +514,7 @@ export const Indicate = forwardRef<HTMLElement, Props & ReactHTMLElementProperti
490
514
position : 'relative' ,
491
515
verticalAlign : 'top' ,
492
516
display : 'inline-flex' ,
517
+ ...innerStyle ,
493
518
...theme . innerWrapper ,
494
519
} ,
495
520
} ,
@@ -523,10 +548,10 @@ export const Indicate = forwardRef<HTMLElement, Props & ReactHTMLElementProperti
523
548
} ,
524
549
< div
525
550
style = { {
526
- ...innerStyle ,
527
551
position : 'relative' ,
528
552
display : 'inline-flex' ,
529
553
verticalAlign : 'top' ,
554
+ ...innerStyle ,
530
555
...theme . innerWrapper ,
531
556
} }
532
557
ref = { innerWrapperRef }
@@ -543,7 +568,6 @@ export const Indicate = forwardRef<HTMLElement, Props & ReactHTMLElementProperti
543
568
style = { {
544
569
...outerStyle ,
545
570
position : 'relative' ,
546
- ...( childAsElement && { overflow : 'auto' } ) ,
547
571
...( isInline && { display : 'inline-block' } ) ,
548
572
...theme . outerWrapper ,
549
573
} }
0 commit comments