Skip to content

Commit dd49656

Browse files
Merge pull request #749 from devtron-labs/fix/action-menu-click
refactor: ActionMenuItem - improve layout for consistent click on menu item
2 parents 2aef17c + 9888d50 commit dd49656

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

src/Shared/Components/ActionMenu/ActionMenuItem.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { Icon } from '../Icon'
77
import { getTooltipProps } from '../SelectPicker/common'
88
import { ActionMenuItemProps } from './types'
99

10+
const COMMON_ACTION_MENU_ITEM_CLASS = 'flex-grow-1 flex left top dc__gap-8 py-6 px-8'
11+
1012
export const ActionMenuItem = <T extends string | number>({
1113
item,
1214
itemRef,
@@ -52,19 +54,25 @@ export const ActionMenuItem = <T extends string | number>({
5254

5355
const renderContent = () => (
5456
<>
55-
<Tooltip content={label} placement="right">
56-
<span className={`m-0 fs-13 fw-4 lh-20 dc__truncate ${isNegativeType ? 'cr-5' : 'cn-9'}`}>{label}</span>
57-
</Tooltip>
58-
{description &&
59-
(typeof description === 'string' ? (
60-
<span
61-
className={`m-0 fs-12 fw-4 lh-18 cn-7 ${!disableDescriptionEllipsis ? 'dc__ellipsis-right__2nd-line' : 'dc__word-break'}`}
62-
>
63-
{description}
57+
{renderIcon(startIcon)}
58+
<span>
59+
<Tooltip content={label} placement="right">
60+
<span className={`m-0 fs-13 fw-4 lh-20 dc__truncate ${isNegativeType ? 'cr-5' : 'cn-9'}`}>
61+
{label}
6462
</span>
65-
) : (
66-
description
67-
))}
63+
</Tooltip>
64+
{description &&
65+
(typeof description === 'string' ? (
66+
<span
67+
className={`m-0 fs-12 fw-4 lh-18 cn-7 ${!disableDescriptionEllipsis ? 'dc__ellipsis-right__2nd-line' : 'dc__word-break'}`}
68+
>
69+
{description}
70+
</span>
71+
) : (
72+
description
73+
))}
74+
</span>
75+
{renderIcon(endIcon)}
6876
</>
6977
)
7078

@@ -74,7 +82,7 @@ export const ActionMenuItem = <T extends string | number>({
7482
return (
7583
<a
7684
ref={itemRef as LegacyRef<HTMLAnchorElement>}
77-
className="flex-grow-1"
85+
className={COMMON_ACTION_MENU_ITEM_CLASS}
7886
href={item.href}
7987
target="_blank"
8088
rel="noreferrer"
@@ -84,7 +92,11 @@ export const ActionMenuItem = <T extends string | number>({
8492
)
8593
case 'link':
8694
return (
87-
<Link ref={itemRef as Ref<HTMLAnchorElement>} className="flex-grow-1" to={item.to}>
95+
<Link
96+
ref={itemRef as Ref<HTMLAnchorElement>}
97+
className={COMMON_ACTION_MENU_ITEM_CLASS}
98+
to={item.to}
99+
>
88100
{renderContent()}
89101
</Link>
90102
)
@@ -94,7 +106,7 @@ export const ActionMenuItem = <T extends string | number>({
94106
<button
95107
ref={itemRef as LegacyRef<HTMLButtonElement>}
96108
type="button"
97-
className="dc__transparent p-0 flex-grow-1"
109+
className={`dc__transparent ${COMMON_ACTION_MENU_ITEM_CLASS}`}
98110
>
99111
{renderContent()}
100112
</button>
@@ -111,13 +123,11 @@ export const ActionMenuItem = <T extends string | number>({
111123
onMouseEnter={onMouseEnter}
112124
tabIndex={-1}
113125
// Intentionally added margin to the left and right to have the gap on the edges of the options
114-
className={`action-menu__option br-4 flex left top dc__gap-8 mr-4 ml-4 py-6 px-8 ${isDisabled ? 'dc__disabled' : 'cursor'} ${isNegativeType ? 'dc__hover-r50' : 'dc__hover-n50'} ${isFocused ? `action-menu__option--focused${isNegativeType ? '-negative' : ''}` : ''}`}
126+
className={`action-menu__option br-4 mr-4 ml-4 ${isDisabled ? 'dc__disabled' : 'cursor'} ${isNegativeType ? 'dc__hover-r50' : 'dc__hover-n50'} ${isFocused ? `action-menu__option--focused${isNegativeType ? '-negative' : ''}` : ''}`}
115127
onClick={!isDisabled ? handleClick : undefined}
116128
aria-disabled={isDisabled}
117129
>
118-
{renderIcon(startIcon)}
119130
{renderComponent()}
120-
{renderIcon(endIcon)}
121131
</li>
122132
</Tooltip>
123133
)

0 commit comments

Comments
 (0)