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

update(Tooltip): Render Popover's popup in Overlay component #392

Merged
merged 3 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions packages/core/src/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ export type TooltipProps = {
content: NonNullable<React.ReactNode>;
/** True to disable tooltip but still show children. */
disabled?: boolean;
/** Manually override calculated horizontal align */
/** Manually override calculated horizontal align. */
horizontalAlign?: 'center' | 'left' | 'right';
/** True to use a light background with dark text. */
inverted?: boolean;
/** Callback fired when the tooltip is closed. */
onClose?: () => void;
/** Callback fired when the tooltip is shown. */
onShow?: () => void;
/** True to enable interactive popover functionality */
/** True to enable interactive popover functionality. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding these 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np, I said I would in the last PR :)

popover?: boolean;
/** True to prevent dismissmal on mouse down. */
remainOnMouseDown?: boolean;
/** True to toggle tooltip display on click. */
toggleOnClick?: boolean;
/** True to add a dotted bottom border. */
underlined?: boolean;
/** Manually override calculated vertical align */
/** Manually override calculated vertical align. */
verticalAlign?: 'above' | 'below';
/** Width of the tooltip in units. */
width?: number;
Expand Down Expand Up @@ -314,23 +314,17 @@ export class Tooltip extends React.Component<TooltipProps & WithStylesProps, Too
marginTop: above ? -(tooltipHeight + targetRect.height + distance) : distance,
textAlign: align,
})}
onMouseEnter={handleMouseEnter}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you elaborate on why this change was needed? Seems fine, wanted to check that the margin areas didn't trigger the event listeners tho (like to the top/left of the actual content)

Copy link
Author

@espressoroaster espressoroaster Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to check that the margin areas didn't trigger the event listeners tho (like to the top/left of the actual content)

I can assure this is ok with a gif (hacked in a larger margin so we can see the gif easily).
margins-no-problem

can you elaborate on why this change was needed?

Yesterday Erik and I ran into a weird case where if the mouse was on the trigger while the popup was opening in the direction the mouse came from, there wouldn't be a continuity between mouse enter trigger -> mouse leave trigger (because of the popup animation) -> mouse entering popup -> mouse leaving popup (when animations passes the cursor) -> mouse back on trigger.

Oddly enough, I don't seem to be encountering that today if I move the mouse handlers back down to the content div. But the first screenshot shows margins weren't causing an issue with the current implementation, so I think the handlers should be fine on either div.

continuity

onMouseLeave={handleMouseLeave}
>
<div
className={cx(styles.content, invert && styles.content_inverted)}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<div className={cx(styles.content, invert && styles.content_inverted)}>
<Text inverted={invert}>{content}</Text>
</div>
</div>
);

if (popover) {
return open && <div className={cx(styles.popover)}>{popupContent}</div>;
}

return (
<Overlay noBackground open={open} onClose={this.handleClose}>
<Overlay noBackground enableMouseInteraction={popover} open={open} onClose={this.handleClose}>
{popupContent}
</Overlay>
);
Expand Down
51 changes: 51 additions & 0 deletions packages/core/src/components/Tooltip/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import LoremIpsum from ':storybook/components/LoremIpsum';
import { withexpandMultiple } from '../Accordion/story';
import Button from '../Button';
import DataTable from '../DataTable';
import { RendererProps } from '../DataTable/types';
import Text from '../Text';
import Spacing from '../Spacing';
import Link from '../Link';
Expand Down Expand Up @@ -389,3 +391,52 @@ export function popoverExpandsAndShrinksWithContent() {
popoverExpandsAndShrinksWithContent.story = {
name: 'Popover expands and shrinks with content.',
};

export function popoverEscapesDataTableRow() {
return (
<DataTable
showRowDividers
data={[
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
]}
keys={['name']}
renderers={{
name: ({ row }: RendererProps<{ name: string }>) => {
const { name } = row.rowData.data;

return (
<Tooltip
popover
content={
<>
<Text bold>Certified by {name}</Text>
<div>
<LoremIpsum short />
</div>
<Link openInNewWindow href="https://github.com/airbnb/lunar">
Click me!
</Link>
</>
}
>
<Text>{name}</Text>
</Tooltip>
);
},
}}
/>
);
}

popoverEscapesDataTableRow.story = {
name: 'Popover can escape a DataTable row.',
};
5 changes: 0 additions & 5 deletions packages/core/src/components/Tooltip/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,4 @@ export const styleSheetTooltip: StyleSheet = ({ unit, color, pattern, ui }) => (
color: color.base,
backgroundColor: color.baseInverse,
},

popover: {
position: 'absolute',
zIndex: 1,
},
});