Skip to content

Commit

Permalink
Add idealDirection to tooltip and iconWithTooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Chong Yao authored and christianvuerings committed Feb 28, 2020
1 parent 4e9267f commit 2c76615
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -8,9 +8,10 @@

### Minor

- Modal: [Docs] Fix default value for closeOnOutsideClick (#697)
- Tooltip: Add ability to hover over tooltip and add a clickable link (#684)
- Tooltip: Add idealDirection (#701)
- IconWithTooltip: deprecate component (#690)
- Modal: [Docs] Fix default value for closeOnOutsideClick (#697)

### Patch

Expand Down
5 changes: 5 additions & 0 deletions docs/src/Tooltip.doc.js
Expand Up @@ -25,6 +25,11 @@ card(
required: true,
description: 'The element to wrap with a tooltip on hover.',
},
{
name: 'idealDirection',
type: `'up' | 'right' | 'down' | 'left'`,
description: 'Preferred direction for the Flyout to open',
},
{
name: 'inline',
type: 'boolean',
Expand Down
11 changes: 9 additions & 2 deletions packages/gestalt/src/Tooltip.js
Expand Up @@ -11,6 +11,7 @@ const TIMEOUT = 100;
type Props = {|
children: React.Node,
link?: React.Node,
idealDirection?: 'up' | 'right' | 'down' | 'left',
inline?: boolean,
text: string,
|};
Expand Down Expand Up @@ -48,7 +49,13 @@ const reducer = (state, action) => {
}
};

export default function Tooltip({ children, link, inline, text }: Props) {
export default function Tooltip({
children,
link,
idealDirection = 'down',
inline,
text,
}: Props) {
const [state, dispatch] = React.useReducer(reducer, initialState);
const { isOpen } = state;

Expand Down Expand Up @@ -90,7 +97,7 @@ export default function Tooltip({ children, link, inline, text }: Props) {
anchor={anchor}
caret={false}
bgColor="darkGray"
idealDirection="down"
idealDirection={idealDirection}
onDismiss={noop}
positionRelativeToAnchor
size={null}
Expand Down
10 changes: 10 additions & 0 deletions packages/gestalt/src/Tooltip.jsdom.test.js
Expand Up @@ -49,3 +49,13 @@ test('Tooltip should render as expected when hovered', () => {
fireEvent.mouseEnter(container.querySelector('[aria-label]'));
expect(getByText('This is a tooltip')).toBeVisible();
});

test('Tooltip renders with idealDirection', () => {
const component = create(
<Tooltip text="This is a tooltip" idealDirection="up">
<div>Hi</div>
</Tooltip>
);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
17 changes: 17 additions & 0 deletions packages/gestalt/src/__snapshots__/Tooltip.jsdom.test.js.snap
Expand Up @@ -16,3 +16,20 @@ exports[`Tooltip renders 1`] = `
</div>
</div>
`;

exports[`Tooltip renders with idealDirection 1`] = `
<div
className="box xsDisplayBlock"
>
<div
aria-label="This is a tooltip"
className="box"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<div>
Hi
</div>
</div>
</div>
`;

0 comments on commit 2c76615

Please sign in to comment.