@codecademy/gamut

68.2.268.2.3-alpha.809fdd.0
dist/Menu/MenuItem.js
~dist/Menu/MenuItem.jsModified
+10−6
Index: package/dist/Menu/MenuItem.js
===================================================================
--- package/dist/Menu/MenuItem.js
+++ package/dist/Menu/MenuItem.js
@@ -14,8 +14,15 @@
   link: 'current page',
   button: 'current action',
   item: 'current item'
 };
+/**
+ * Narrows the forwarded ref union to a specific element type for the current render branch.
+ * MenuItem renders exactly one of li, a, or button per call, so the ref is forwarded to that element.
+ */
+function narrowMenuItemRef(ref) {
+  return ref;
+}
 export const MenuItem = /*#__PURE__*/forwardRef(({
   active,
   children,
   disabled,
@@ -69,48 +76,45 @@
       children: [currentItemText[listItemType], ","]
     }), children]
   });
   if (listItemType === 'link' && !disabled) {
-    const linkRef = ref;
     return /*#__PURE__*/_jsx(ListItem, {
       ...listItemProps,
       children: /*#__PURE__*/_jsx(MenuToolTipWrapper, {
         label: label,
         tipId: tipId,
         children: /*#__PURE__*/_jsx(ListLink, {
           ...computed,
           href: href,
-          ref: linkRef,
+          ref: narrowMenuItemRef(ref),
           target: target,
           children: content
         })
       })
     });
   }
   if (listItemType === 'button' || listItemType === 'link' && disabled) {
-    const buttonRef = ref;
     const handleClick = disabled ? () => null : props.onClick;
     return /*#__PURE__*/_jsx(ListItem, {
       ...listItemProps,
       children: /*#__PURE__*/_jsx(MenuToolTipWrapper, {
         label: label,
         tipId: tipId,
         children: /*#__PURE__*/_jsx(ListButton, {
           ...computed,
-          ref: buttonRef,
+          ref: narrowMenuItemRef(ref),
           onClick: handleClick,
           children: content
         })
       })
     });
   }
-  const liRef = ref;
   return (
     /*#__PURE__*/
     // These are non-interactive and will never have tooltips (nor should they).
     _jsx(ListItem, {
       ...computed,
-      ref: liRef,
+      ref: narrowMenuItemRef(ref),
       children: content
     })
   );
 });
\ No newline at end of file