diff --git a/src/components/Menu/MenuItem/MenuItem.jsx b/src/components/Menu/MenuItem/MenuItem.jsx index 3b05f14f25..474767c0da 100644 --- a/src/components/Menu/MenuItem/MenuItem.jsx +++ b/src/components/Menu/MenuItem/MenuItem.jsx @@ -45,6 +45,7 @@ const MenuItem = forwardRef( setSubMenuIsOpenByIndex, closeMenu, useDocumentEventListeners, + tooltipContent, tooltipPosition, tooltipShowDelay, isInitialSelectedState, @@ -209,8 +210,13 @@ const MenuItem = forwardRef( }; }, [children, hasOpenSubMenu]); - const shouldShowTooltip = isTitleHoveredAndOverflowing || disabled; - const tooltipContent = disabled ? disableReason : title; + const shouldShowTooltip = isTitleHoveredAndOverflowing || disabled || tooltipContent; + + const finalTooltipContent = useMemo(() => { + if (disabled) return disableReason; + if (tooltipContent) return tooltipContent; + return title; + }, [disableReason, disabled, title, tooltipContent]); return ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events @@ -234,7 +240,7 @@ const MenuItem = forwardRef( {renderMenuItemIconIfNeeded()} @@ -293,6 +299,7 @@ MenuItem.defaultProps = { setSubMenuIsOpenByIndex: undefined, resetOpenSubMenuIndex: undefined, useDocumentEventListeners: false, + tooltipContent: undefined, tooltipPosition: MenuItem.tooltipPositions.RIGHT, tooltipShowDelay: 300, onMouseLeave: undefined, @@ -318,6 +325,7 @@ MenuItem.propTypes = { hasOpenSubMenu: PropTypes.bool, setSubMenuIsOpenByIndex: PropTypes.func, useDocumentEventListeners: PropTypes.bool, + tooltipContent: PropTypes.string, tooltipPosition: PropTypes.oneOf([ MenuItem.tooltipPositions.RIGHT, MenuItem.tooltipPositions.LEFT, diff --git a/src/components/Menu/MenuItem/__stories__/MenuItem.stories.js b/src/components/Menu/MenuItem/__stories__/MenuItem.stories.js index b09221eb1e..dd3d8b2558 100644 --- a/src/components/Menu/MenuItem/__stories__/MenuItem.stories.js +++ b/src/components/Menu/MenuItem/__stories__/MenuItem.stories.js @@ -66,3 +66,18 @@ export const menuItemOverflowTemplate = args => { ); }; + +export const menuItemTooltipTemplate = args => { + return ( + + + + + + + ); +}; diff --git a/src/components/Menu/MenuItem/__stories__/MenuItem.stories.mdx b/src/components/Menu/MenuItem/__stories__/MenuItem.stories.mdx index 55c920a1a0..e6f5bea92e 100644 --- a/src/components/Menu/MenuItem/__stories__/MenuItem.stories.mdx +++ b/src/components/Menu/MenuItem/__stories__/MenuItem.stories.mdx @@ -4,7 +4,9 @@ import { menuItemTemplate, menuItemStatesTemplate, menuItemIconsTemplate, - menuItemIconsWithColorsTemplate, menuItemOverflowTemplate + menuItemIconsWithColorsTemplate, + menuItemOverflowTemplate, + menuItemTooltipTemplate } from "./MenuItem.stories"; import MenuItem from "../MenuItem"; @@ -16,14 +18,15 @@ export const metaSettings = createStoryMetaSettings({ # Menu Item + - [Overview](#overview) - [Props](#props) - [Use cases and examples](#use-cases-and-examples) @@ -31,42 +34,47 @@ export const metaSettings = createStoryMetaSettings({ - [Feedback](#feedback) ## Overview + Use menu item for drawing one options that displayed inside a menu. - - { menuItemTemplate.bind({}) } + + {menuItemTemplate.bind({})} ## Props - + + ## Variants + ### States + - - { menuItemStatesTemplate.bind({}) } - + {menuItemStatesTemplate.bind({})} ### Icons + - - { menuItemIconsTemplate.bind({}) } - + {menuItemIconsTemplate.bind({})} ### Icons with colors + - - { menuItemIconsWithColorsTemplate.bind({}) } - + {menuItemIconsWithColorsTemplate.bind({})} ### Overflow + - - { menuItemOverflowTemplate.bind({}) } - - \ No newline at end of file + {menuItemOverflowTemplate.bind({})} + + +### Tooltips + + + {menuItemTooltipTemplate.bind({})} +