Skip to content

Commit

Permalink
feat(Popover/Tooltip): ability to pass through flip prop (#1443)
Browse files Browse the repository at this point in the history
Popovers and tooltips by default get flipped by Popper if they're close to
the edge of the screen; this allows us to override that
  • Loading branch information
pxpeterxu authored and TheSharpieOne committed Apr 3, 2019
1 parent 04be99f commit 4a5a8a3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
11 changes: 10 additions & 1 deletion docs/lib/Components/PopoversPage.js
Expand Up @@ -77,7 +77,16 @@ export default class PopoversPage extends React.Component {
offset: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
])
]),
// Whether to show/hide the popover with a fade effect
// (default: true)
fade: PropTypes.bool,
// Whether to flip the direction of the popover if too close to
// the container edge
// (default: true)
flip: PropTypes.bool,
}`}
</PrismCode>
</pre>
Expand Down
11 changes: 10 additions & 1 deletion docs/lib/Components/TooltipsPage.js
Expand Up @@ -88,7 +88,16 @@ export default class TooltipsPage extends React.Component {
PropTypes.func,
PropTypes.string,
PropTypes.object
])
]),
// Whether to show/hide the popover with a fade effect
// (default: true)
fade: PropTypes.bool,
// Whether to flip the direction of the popover if too close to
// the container edge
// (default: true)
flip: PropTypes.bool,
}`}
</PrismCode>
</pre>
Expand Down
3 changes: 3 additions & 0 deletions src/TooltipPopoverWrapper.js
Expand Up @@ -39,6 +39,7 @@ export const propTypes = {
]),
trigger: PropTypes.string,
fade: PropTypes.bool,
flip: PropTypes.bool,
};

const DEFAULT_DELAYS = {
Expand Down Expand Up @@ -312,6 +313,7 @@ class TooltipPopoverWrapper extends React.Component {
modifiers,
offset,
fade,
flip,
} = this.props;

const attributes = omit(this.props, Object.keys(propTypes));
Expand All @@ -337,6 +339,7 @@ class TooltipPopoverWrapper extends React.Component {
cssModule={cssModule}
onClosed={this.onClosed}
fade={fade}
flip={flip}
>
<div
{...attributes}
Expand Down
15 changes: 13 additions & 2 deletions src/__tests__/TooltipPopoverWrapper.spec.js
Expand Up @@ -236,7 +236,7 @@ describe('Tooltip', () => {
</TooltipPopoverWrapper>,
{ attachTo: container }
);

expect(isOpen).toBe(false);
target.dispatchEvent(new Event('touchstart'));
jest.runTimersToTime(20);
Expand All @@ -256,7 +256,7 @@ describe('Tooltip', () => {
</TooltipPopoverWrapper>,
{ attachTo: container }
);

expect(isOpen).toBe(true);
target.dispatchEvent(new Event('touchstart'));
jest.runTimersToTime(20);
Expand Down Expand Up @@ -315,6 +315,17 @@ describe('Tooltip', () => {
wrapper.unmount();
});

it('should pass down flip', () => {
const wrapper = mount(
<TooltipPopoverWrapper isOpen target="target" flip={false}>
Tooltip Content
</TooltipPopoverWrapper>
);

expect(wrapper.find(PopperContent).props().flip).toBe(false);
wrapper.unmount();
});

it('should not call props.toggle when disabled ', () => {
const props = createSpyObj('props', ['toggle']);
const event = createSpyObj('event', ['preventDefault']);
Expand Down

0 comments on commit 4a5a8a3

Please sign in to comment.