Skip to content

Commit 3c87aee

Browse files
add example, change desc, add const for offset, improve test
1 parent 3ec395c commit 3c87aee

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Added an optional `offset` prop to `EuiToolTip` to allow customizing the distance (in pixels) between the tooltip and its anchor. The default value is `16`.
1+
- Added an optional `offset` prop to `EuiToolTip` to allow customizing the distance (in pixels) between the tooltip and its anchor.

packages/eui/src/components/tool_tip/tool_tip.stories.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import { LOKI_SELECTORS, lokiPlayDecorator } from '../../../.storybook/loki';
1414
import { sleep } from '../../test';
1515
import { EuiFlexGroup } from '../flex';
1616
import { EuiButton } from '../button';
17-
import { EuiToolTip, EuiToolTipProps } from './tool_tip';
17+
import {
18+
EuiToolTip,
19+
EuiToolTipProps,
20+
DEFAULT_TOOLTIP_OFFSET,
21+
} from './tool_tip';
1822

1923
const meta: Meta<EuiToolTipProps> = {
2024
title: 'Display/EuiToolTip',
@@ -47,7 +51,7 @@ const meta: Meta<EuiToolTipProps> = {
4751
repositionOnScroll: false,
4852
title: '',
4953
disableScreenReaderOutput: false,
50-
offset: 16,
54+
offset: DEFAULT_TOOLTIP_OFFSET,
5155
},
5256
};
5357
enableFunctionToggleControls(meta, ['onMouseOut']);

packages/eui/src/components/tool_tip/tool_tip.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import React, { useRef } from 'react';
10-
import { fireEvent, within } from '@testing-library/react';
10+
import { fireEvent } from '@testing-library/react';
1111
import { userEvent } from '@storybook/test';
1212
import {
1313
render,
@@ -64,12 +64,12 @@ describe('EuiToolTip', () => {
6464

6565
it('uses custom offset prop value', async () => {
6666
const offsetValue = 32;
67-
const { baseElement } = render(
67+
const { baseElement, getByRole } = render(
6868
<EuiToolTip content="content" offset={offsetValue} {...requiredProps}>
6969
<button data-test-subj="trigger">Trigger</button>
7070
</EuiToolTip>
7171
);
72-
const trigger = within(baseElement).getByRole('button');
72+
const trigger = getByRole('button');
7373

7474
await userEvent.hover(trigger);
7575
await waitForEuiToolTipVisible();

packages/eui/src/components/tool_tip/tool_tip.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const POSITIONS = ['top', 'right', 'bottom', 'left'] as const;
3131
const DISPLAYS = ['inlineBlock', 'block'] as const;
3232

3333
export type ToolTipDelay = 'regular' | 'long';
34+
export const DEFAULT_TOOLTIP_OFFSET = 16;
3435

3536
const delayToMsMap: { [key in ToolTipDelay]: number } = {
3637
regular: 250,
@@ -123,7 +124,7 @@ export interface EuiToolTipProps extends CommonProps {
123124
onMouseOut?: (event: ReactMouseEvent<HTMLSpanElement, MouseEvent>) => void;
124125

125126
/**
126-
* Offset in pixels from the anchor. Defaults to 16.
127+
* You can adjust the distance between the tooltip and its anchor using the `offset` prop. By default, this value is `16`.
127128
*/
128129
offset?: number;
129130
}
@@ -225,7 +226,7 @@ export class EuiToolTip extends Component<EuiToolTipProps, State> {
225226

226227
positionToolTip = () => {
227228
const requestedPosition = this.props.position;
228-
const offset = this.props.offset ?? 16;
229+
const offset = this.props.offset ?? DEFAULT_TOOLTIP_OFFSET;
229230

230231
if (!this.anchor || !this.popover) {
231232
return;

packages/website/docs/components/display/tooltip.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export default () => (
6565
<EuiIcon tabIndex="0" type="warning" title="Icon with tooltip" />
6666
</EuiToolTip>
6767
</p>
68+
<p>
69+
This tooltip has a{' '}
70+
<EuiToolTip position="right" content="Here is some tooltip text" offset={32}>
71+
<EuiLink href="#">custom offset</EuiLink>
72+
</EuiToolTip>
73+
</p>
6874
</EuiText>
6975
</div>
7076
);

0 commit comments

Comments
 (0)