Skip to content

Commit

Permalink
Merge pull request #312 from dcos-labs/brandonc/callback_close_tooltip
Browse files Browse the repository at this point in the history
feat(ui): onClose callback on tooltip
  • Loading branch information
GeorgiSTodorov authored Mar 15, 2019
2 parents f45b1e6 + ec86f0e commit 5f96cac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/tooltip/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface TooltipProps extends BaseTooltipProps {
open?: boolean;
suppress?: boolean;
trigger: React.ReactNode;
onClose?: () => void;
}

export interface TooltipState {
Expand Down Expand Up @@ -99,7 +100,11 @@ class Tooltip extends React.PureComponent<TooltipProps, TooltipState> {
return;
}

this.setState({ open: false });
this.setState({ open: false }, () => {
if (this.props.onClose) {
this.props.onClose();
}
});
}
}

Expand Down
14 changes: 14 additions & 0 deletions packages/tooltip/tests/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,18 @@ describe("Tooltip", () => {
component.simulate("mouseEnter");
expect(component.state("open")).toBe(false);
});

it("calls onClose prop when closed", () => {
const handleClose = jest.fn();

const component = mount(
<Tooltip id="hoverOpen" trigger="trigger" onClose={handleClose}>
content
</Tooltip>
);

component.simulate("mouseEnter");
component.simulate("mouseLeave");
expect(handleClose).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 5f96cac

Please sign in to comment.