File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -413,4 +413,29 @@ describe('OverflowMenu', () => {
413
413
expect ( button ) . not . toHaveClass ( 'cds--overflow-menu--open' ) ;
414
414
expect ( button ) . toHaveFocus ( ) ;
415
415
} ) ;
416
+ describe ( 'Ref handling' , ( ) => {
417
+ it ( 'should support both standard ref and innerRef' , ( ) => {
418
+ const standardRef = React . createRef ( ) ;
419
+ const innerRef = React . createRef ( ) ;
420
+
421
+ render (
422
+ < OverflowMenu
423
+ ref = { standardRef }
424
+ innerRef = { innerRef }
425
+ aria-label = "Overflow menu"
426
+ data-testid = "overflow-menu" >
427
+ < OverflowMenuItem itemText = "Option 1" />
428
+ < OverflowMenuItem itemText = "Option 2" />
429
+ </ OverflowMenu >
430
+ ) ;
431
+ const buttonElement = screen . getByRole ( 'button' ) ;
432
+ expect ( standardRef . current ) . not . toBeNull ( ) ;
433
+ expect ( innerRef . current ) . not . toBeNull ( ) ;
434
+ expect ( standardRef . current ) . toBe ( buttonElement ) ;
435
+ expect ( innerRef . current ) . toBe ( buttonElement ) ;
436
+
437
+ // Verify both refs point to the same element & not null
438
+ expect ( standardRef . current ) . toBe ( innerRef . current ) ;
439
+ } ) ;
440
+ } ) ;
416
441
} ) ;
Original file line number Diff line number Diff line change @@ -229,7 +229,8 @@ export interface OverflowMenuProps {
229
229
size ?: 'sm' | 'md' | 'lg' ;
230
230
231
231
/**
232
- * The ref to the HTML element that should receive focus when the OverflowMenu opens
232
+ * The ref to the overflow menu's trigger button element.
233
+ * @deprecated Use the standard React `ref` prop instead.
233
234
*/
234
235
innerRef ?: Ref < any > ;
235
236
}
@@ -258,6 +259,7 @@ export const OverflowMenu = forwardRef<HTMLButtonElement, OverflowMenuProps>(
258
259
renderIcon : IconElement = OverflowMenuVertical ,
259
260
selectorPrimaryFocus = '[data-floating-menu-primary-focus]' ,
260
261
size = 'md' ,
262
+ innerRef,
261
263
...other
262
264
} ,
263
265
ref
@@ -543,6 +545,9 @@ export const OverflowMenu = forwardRef<HTMLButtonElement, OverflowMenuProps>(
543
545
} ) }
544
546
</ FloatingMenu >
545
547
) ;
548
+ const combinedRef = innerRef
549
+ ? mergeRefs ( triggerRef , innerRef , ref )
550
+ : mergeRefs ( triggerRef , ref ) ;
546
551
547
552
return (
548
553
< >
@@ -559,7 +564,7 @@ export const OverflowMenu = forwardRef<HTMLButtonElement, OverflowMenuProps>(
559
564
className = { overflowMenuClasses }
560
565
onClick = { handleClick }
561
566
id = { id }
562
- ref = { mergeRefs ( triggerRef , ref ) }
567
+ ref = { combinedRef }
563
568
size = { size }
564
569
label = { iconDescription }
565
570
kind = "ghost" >
You can’t perform that action at this time.
0 commit comments