Skip to content

Commit

Permalink
Fix collapsed action to have the same tooltip delay as non-collapsed …
Browse files Browse the repository at this point in the history
…actions

- this involves adding `toolTipProps` to `EuiContextMenuItem`

- deprecate a few other top-level tooltip props while here, for simpler API usage
  • Loading branch information
cee-chen committed Nov 17, 2023
1 parent d29b623 commit cdc1c39
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
6 changes: 6 additions & 0 deletions changelogs/upcoming/7373.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
- Updated the actions column in `EuiBasicTable` and `EuiInMemoryTable`s. Alongside `name`, the `description`, `href`, and `data-test-subj` properties now also accept an optional callback that the current `item` will be passed to
- Updated `EuiContextMenuItem` with a new `toolTipProps` prop

**Bug fixes**

- Fixed non-`isPrimary` actions (collapsed within a popover) not showing the action description in a tooltip

**Deprecations**

- Deprecated `EuiContextMenuItem`'s `toolTipTitle` prop. Use `toolTipProps.title` instead
- Deprecated `EuiContextMenuItem`'s `toolTipPosition` prop. Use `toolTipProps.position` instead
1 change: 1 addition & 0 deletions src/components/basic_table/collapsed_item_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const CollapsedItemActions = <T extends {}>({
onClickItem(onClick ? () => onClick(item) : undefined)
}
toolTipContent={toolTipContent}
toolTipProps={{ delay: 'long' }}
>
{buttonContent}
</EuiContextMenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,52 @@ exports[`EuiContextMenuItem renders 1`] = `
</span>
</a>
`;

exports[`EuiContextMenuItem tooltip behavior 1`] = `
<body
class="euiBody-hasPortalContent"
>
<div>
<span
class="euiToolTipAnchor eui-displayBlock emotion-euiToolTipAnchor-inlineBlock"
>
<button
aria-describedby="generated-id"
class="euiContextMenuItem emotion-euiContextMenuItem-m-center"
type="button"
>
<span
class="euiContextMenuItem__text emotion-euiContextMenuItem__text"
>
Hello
</span>
</button>
</span>
</div>
<div
data-euiportal="true"
>
<div
class="euiToolTipPopover euiToolTip emotion-euiToolTip-top"
data-position="top"
id="generated-id"
position="top"
role="tooltip"
style="top: -16px; left: -10px;"
>
<div
class="euiToolTip__title emotion-euiToolTip__title"
>
Test
</div>
<div
class="euiToolTip__arrow emotion-euiToolTip__arrow-top"
style="left: 4px; top: 0px;"
/>
<div>
tooltip content
</div>
</div>
</div>
</body>
`;
32 changes: 31 additions & 1 deletion src/components/context_menu/context_menu_item.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react';
import { fireEvent } from '@testing-library/react';
import { render } from '../../test/rtl';
import { render, waitForEuiToolTipVisible } from '../../test/rtl';
import { shouldRenderCustomStyles } from '../../test/internal';
import { requiredProps } from '../../test/required_props';

Expand All @@ -17,6 +17,18 @@ import { EuiContextMenuItem, SIZES } from './context_menu_item';
describe('EuiContextMenuItem', () => {
shouldRenderCustomStyles(<EuiContextMenuItem />);

shouldRenderCustomStyles(
<EuiContextMenuItem toolTipContent="test" data-test-subj="trigger" />,
{
childProps: ['toolTipProps', 'toolTipProps.anchorProps'],
skip: { parentTest: true },
renderCallback: async ({ getByTestSubject }) => {
fireEvent.mouseOver(getByTestSubject('trigger'));
await waitForEuiToolTipVisible();
},
}
);

it('renders', () => {
const { container } = render(
<EuiContextMenuItem {...requiredProps} href="url">
Expand Down Expand Up @@ -121,4 +133,22 @@ describe('EuiContextMenuItem', () => {
).toBeInTheDocument();
});
});

test('tooltip behavior', async () => {
const { getByRole, baseElement } = render(
<EuiContextMenuItem
toolTipContent="tooltip content"
toolTipTitle="overridden"
// Should override the deprecated props
toolTipProps={{ title: 'Test', position: 'top', delay: 'long' }}
>
Hello
</EuiContextMenuItem>
);

fireEvent.mouseOver(getByRole('button'));
await waitForEuiToolTipVisible();

expect(baseElement).toMatchSnapshot();
});
});
23 changes: 17 additions & 6 deletions src/components/context_menu/context_menu_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { validateHref } from '../../services/security/href_validator';
import { CommonProps, keysOf } from '../common';
import { EuiIcon } from '../icon';
import { EuiToolTip, ToolTipPositions } from '../tool_tip';
import { EuiToolTip, EuiToolTipProps, ToolTipPositions } from '../tool_tip';

import { euiContextMenuItemStyles } from './context_menu_item.styles';

Expand All @@ -46,11 +46,16 @@ export interface EuiContextMenuItemProps extends CommonProps {
*/
toolTipContent?: ReactNode;
/**
* Optional title for the tooltip
* Optional configuration to pass to the underlying [EuiToolTip](/#/display/tooltip).
* Accepts any prop that EuiToolTip does, except for `content` and `children`.
*/
toolTipProps?: Partial<Omit<EuiToolTipProps, 'content' | 'children'>>;
/**
* @deprecated Use toolTipProps.title instead
*/
toolTipTitle?: ReactNode;
/**
* Dictates the position of the tooltip.
* @deprecated Use tooltipProps.position instead
*/
toolTipPosition?: ToolTipPositions;
href?: string;
Expand Down Expand Up @@ -94,6 +99,7 @@ export const EuiContextMenuItem: FunctionComponent<Props> = ({
toolTipTitle,
toolTipContent,
toolTipPosition = 'right',
toolTipProps,
href,
target,
rel,
Expand Down Expand Up @@ -173,7 +179,7 @@ export const EuiContextMenuItem: FunctionComponent<Props> = ({
{buttonContent}
</a>
);
} else if (href || rest.onClick) {
} else if (href || rest.onClick || toolTipContent) {
button = (
<button
disabled={disabled}
Expand All @@ -200,12 +206,17 @@ export const EuiContextMenuItem: FunctionComponent<Props> = ({
}

if (toolTipContent) {
const anchorClasses = classNames(
'eui-displayBlock',
toolTipProps?.anchorClassName
);
return (
<EuiToolTip
title={toolTipTitle ? toolTipTitle : null}
content={toolTipContent}
anchorClassName="eui-displayBlock"
position={toolTipPosition}
{...toolTipProps}
anchorClassName={anchorClasses}
content={toolTipContent}
>
{button}
</EuiToolTip>
Expand Down

0 comments on commit cdc1c39

Please sign in to comment.