Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds display prop to EuiTooltip for common display block needs #4148

Merged
merged 11 commits into from
Oct 21, 2020
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test-env/
npm-debug.log
yarn-error.log
.cache-loader
**/*.out
snide marked this conversation as resolved.
Show resolved Hide resolved

# typescript output
types/
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `display` prop to `EuiToolTip` for common display block needs ([#4148](https://github.com/elastic/eui/pull/4148))

**Bug fixes**

- Fix issue with duplicate checkmarks in `EuiComboBox` ([4162](https://github.com/elastic/eui/pull/4162))


## [`30.0.0`](https://github.com/elastic/eui/tree/v30.0.0)

- Deprecated `EuiKeyboardAccessible` ([4135]https://github.com/elastic/eui/pull/4135)
Expand Down
13 changes: 13 additions & 0 deletions src-docs/src/views/tool_tip/tool_tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export default () => (

<EuiSpacer />

<p>
<EuiToolTip
position="top"
content="Here is some tooltip text"
display="block">
<EuiButton fullWidth>
I am a block level tooltip, applied to a button with fullWidth
</EuiButton>
</EuiToolTip>
</p>

<EuiSpacer />

<EuiToolTip position="right" content="Works on anything">
<EuiFieldText
placeholder="Hover over me"
Expand Down
10 changes: 10 additions & 0 deletions src/components/tool_tip/__snapshots__/tool_tip.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiToolTip display prop renders block 1`] = `
<span
class="euiToolTipAnchor euiToolTipAnchor--displayBlock"
>
<button>
Trigger
</button>
</span>
`;

exports[`EuiToolTip is rendered 1`] = `
<span
class="euiToolTipAnchor"
Expand Down
4 changes: 4 additions & 0 deletions src/components/tool_tip/_tool_tip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
*[disabled] {
pointer-events: none;
}

&.euiToolTipAnchor--displayBlock {
display: block;
}
}

// Keyframes to animate in the tooltip.
Expand Down
15 changes: 15 additions & 0 deletions src/components/tool_tip/tool_tip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,19 @@ describe('EuiToolTip', () => {
await sleep(260); // wait for showToolTip setTimout
expect(takeMountedSnapshot(component)).toMatchSnapshot();
});

test('display prop renders block', async () => {
const component = render(
<EuiToolTip
title="title"
id="id"
content="content"
{...requiredProps}
display="block">
<button>Trigger</button>
</EuiToolTip>
);

expect(component).toMatchSnapshot();
});
});
16 changes: 15 additions & 1 deletion src/components/tool_tip/tool_tip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ interface ToolTipStyles {
opacity?: number;
}

const displayToClassNameMap = {
inlineBlock: undefined,
block: 'euiToolTipAnchor--displayBlock',
};

const DEFAULT_TOOLTIP_STYLES: ToolTipStyles = {
// position the tooltip content near the top-left
// corner of the window so it can't create scrollbars
Expand Down Expand Up @@ -89,6 +94,10 @@ export interface Props {
* The main content of your tooltip.
*/
content?: ReactNode;
/**
* Common display alternatives for the anchor wrapper
*/
display?: keyof typeof displayToClassNameMap;
/**
* Delay before showing tooltip. Good for repeatable items.
*/
Expand Down Expand Up @@ -286,6 +295,7 @@ export class EuiToolTip extends Component<Props, State> {
content,
title,
delay,
display = 'inlineBlock',
...rest
} = this.props;

Expand All @@ -297,7 +307,11 @@ export class EuiToolTip extends Component<Props, State> {
className
);

const anchorClasses = classNames('euiToolTipAnchor', anchorClassName);
const anchorClasses = classNames(
'euiToolTipAnchor',
display ? displayToClassNameMap[display] : null,
anchorClassName
);

let tooltip;
if (visible && (content || title)) {
Expand Down