FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(tooltip): allow manual trigger, access to tippy.js props by jeff-phillips-18 · Pull Request #2769 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .snap  (4) .tsx  (4) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ exports[`copy button render 1`] = `
]
}
isAppLauncher={false}
isVisible={false}
maxWidth="500px"
position="right"
tippyProps={Object {}}
trigger="mouseenter focus click"
zIndex={9999}
>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,26 @@ test('popover can specify position as object value', () => {
);
expect(view).toMatchSnapshot();
});

test('popover passes along values to tippy.js', () => {
const view = shallow(
<Popover
position={PopoverPosition.right}
isVisible
hideOnOutsideClick
headerContent={<div>Popover Header</div>}
bodyContent={
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.
</div>
}
tippyProps={{
duration: [200, 200],
offset: 20
}}
>
<div>Tippy Props Test</div>
</Popover>
);
expect(view).toMatchSnapshot();
});
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PopoverBase from '../../helpers/PopoverBase/PopoverBase';
import { Instance as TippyInstance } from 'tippy.js';
import { Instance as TippyInstance, Props as TippyProps } from 'tippy.js';
import { KEY_CODES } from '../../helpers/constants';
import styles from '@patternfly/react-styles/css/components/Popover/popover';
import '@patternfly/react-styles/css/components/Tooltip/tippy.css';
Expand Down Expand Up @@ -46,8 +46,8 @@ export interface PopoverProps {
distance?: number;
/** If true, tries to keep the popover in view by flipping it if necessary */
enableFlip?: boolean;
/**
* The desired position to flip the popover to if the initial position is not possible.
/**
* The desired position to flip the popover to if the initial position is not possible.
* By setting this prop to 'flip' it attempts to flip the popover to the opposite side if there is no space.
* You can also pass an array of positions that determines the flip order. It should contain the initial position
* followed by alternative positions if that position is unavailable.
Expand Down Expand Up @@ -81,8 +81,8 @@ export interface PopoverProps {
onShow?: (tip:TippyInstance) => void;
/** Lifecycle function invoked when the popover has fully transitioned in. */
onShown?: (tip:TippyInstance) => void;
/**
* Popover position. Note: With 'enableFlip' set to true,
/**
* Popover position. Note: With 'enableFlip' set to true,
* it will change the position if there is not enough space for the starting position.
* The behavior of where it flips to can be controlled through the flipBehavior prop.
*/
Expand All @@ -94,7 +94,8 @@ export interface PopoverProps {
shouldClose?: (tip:TippyInstance) => void;
/** z-index of the popover */
zIndex?: number;

/** additional Props to pass through to tippy.js */
tippyProps?: TippyProps;
}

export interface PopoverState {
Expand Down Expand Up @@ -125,7 +126,8 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
distance: 25,
boundary: 'window',
// For every initial starting position, there are 3 escape positions
flipBehavior: ['top', 'right', 'bottom', 'left', 'top', 'right', 'bottom']
flipBehavior: ['top', 'right', 'bottom', 'left', 'top', 'right', 'bottom'],
tippyProps: {}
};

constructor(props: PopoverProps) {
Expand Down Expand Up @@ -226,6 +228,7 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
distance,
boundary,
flipBehavior,
tippyProps,
...rest
} = this.props;

Expand Down Expand Up @@ -274,6 +277,7 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
};
return (
<PopoverBase
{...tippyProps}
arrow
onCreate={this.storeTippyInstance}
maxWidth={maxWidth}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,75 @@ exports[`popover can specify position as object value 1`] = `
</PopoverBase>
`;

exports[`popover passes along values to tippy.js 1`] = `
<PopoverBase
animateFill={false}
appendTo={[Function]}
arrow={true}
boundary="window"
content={
<GenerateId
prefix="pf-random-id-"
>
[Function]
</GenerateId>
}
distance={25}
duration={
Array [
200,
200,
]
}
flip={true}
flipBehavior={
Array [
"top",
"right",
"bottom",
"left",
"top",
"right",
"bottom",
]
}
hideOnClick={false}
interactive={true}
interactiveBorder={0}
isVisible={true}
lazy={true}
maxWidth="calc(2rem + 18.75rem)"
offset={20}
onCreate={[Function]}
onHidden={[Function]}
onHide={[Function]}
onMount={[Function]}
onShow={[Function]}
onShown={[Function]}
performance={true}
placement="right"
popperOptions={
Object {
"modifiers": Object {
"hide": Object {
"enabled": true,
},
"preventOverflow": Object {
"enabled": true,
},
},
}
}
theme="pf-popover"
trigger="manual"
zIndex={9999}
>
<div>
Tippy Props Test
</div>
</PopoverBase>
`;

exports[`popover renders close-button, header and body 1`] = `
<PopoverBase
animateFill={false}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ test('tooltip renders', () => {
expect(view).toMatchSnapshot();
});

test('tooltip passes along values to tippy.js', () => {
const view = shallow(
<Tooltip
position="top"
content={
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.
</div>
}
tippyProps={{
duration: [200, 200],
offset: 20
}}
>
<div>Tippy Props Test</div>
</Tooltip>
);
expect(view).toMatchSnapshot();
});

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PopoverBase from '../../helpers/PopoverBase/PopoverBase';
import { Instance as TippyInstance } from 'tippy.js';
import { Instance as TippyInstance, Props as TippyProps } from 'tippy.js';
import styles from '@patternfly/react-styles/css/components/Tooltip/tooltip';
import '@patternfly/react-styles/css/components/Tooltip/tippy.css';
import '@patternfly/react-styles/css/components/Tooltip/tippy-overrides.css';
Expand Down Expand Up @@ -39,8 +39,8 @@ export interface TooltipProps {
entryDelay?: number;
/** Delay in ms before the tooltip disappears */
exitDelay?: number;
/**
* The desired position to flip the tooltip to if the initial position is not possible.
/**
* The desired position to flip the tooltip to if the initial position is not possible.
* By setting this prop to 'flip' it attempts to flip the tooltip to the opposite side if there is no space.
* You can also pass an array of positions that determines the flip order. It should contain the initial position
* followed by alternative positions if that position is unavailable.
Expand All @@ -53,23 +53,28 @@ export interface TooltipProps {
isAppLauncher?: boolean;
/** Maximum width of the tooltip (default 12.5rem) */
maxWidth?: string;
/**
* Tooltip position. Note: With 'enableFlip' set to true,
/**
* Tooltip position. Note: With 'enableFlip' set to true,
* it will change the position if there is not enough space for the starting position.
* The behavior of where it flips to can be controlled through the flipBehavior prop.
*/
position?: 'auto' | 'top' | 'bottom' | 'left' | 'right';
/** Tooltip trigger: click, mouseenter, focus */
/** Tooltip trigger: click, mouseenter, focus, manual */
trigger?: string;
/** value for visibility when trigger is 'manual' */
isVisible?: boolean;
/** z-index of the tooltip */
zIndex?: number;
/** additional Props to pass through to tippy.js */
tippyProps?: TippyProps;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

i think we should just add what we need in terms of props instead of a passthrough? otherwise could be more maintenance if some tippy props don't behave as expected in our component

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think it's better to allow the full set to be passed thru. How can we know up front which props consumers want to customize? Limiting the options will cause limits to its adoptability. If there are any issues with using a particular prop, then an issue can be raised.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

what about the fact that there'll be duplicate props, for example we expose enableFlip which would be the same as tippyProps.flip

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

whatever props we accept/set will override what is in the tippyProps

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

okay let's go with this, can you also add the passthrough to the Popover component as well then? Thanks

};

export class Tooltip extends React.Component<TooltipProps> {
private tip: TippyInstance;
static defaultProps = {
position: 'top',
trigger: 'mouseenter focus',
isVisible: false,
enableFlip: true,
className: '',
entryDelay: 500,
Expand All @@ -82,7 +87,8 @@ export class Tooltip extends React.Component<TooltipProps> {
aria: 'describedby',
boundary: 'window',
// For every initial starting position, there are 3 escape positions
flipBehavior: ['top', 'right', 'bottom', 'left', 'top', 'right', 'bottom']
flipBehavior: ['top', 'right', 'bottom', 'left', 'top', 'right', 'bottom'],
tippyProps: {}
};

storeTippyInstance = (tip:TippyInstance) => {
Expand Down Expand Up @@ -114,6 +120,7 @@ export class Tooltip extends React.Component<TooltipProps> {
const {
position,
trigger,
isVisible,
enableFlip,
children,
className,
Expand All @@ -128,6 +135,7 @@ export class Tooltip extends React.Component<TooltipProps> {
aria,
boundary,
flipBehavior,
tippyProps,
...rest
} = this.props;
const content = (
Expand All @@ -141,6 +149,7 @@ export class Tooltip extends React.Component<TooltipProps> {
);
return (
<PopoverBase
{...tippyProps}
arrow
aria={aria}
onCreate={this.storeTippyInstance}
Expand All @@ -159,6 +168,7 @@ export class Tooltip extends React.Component<TooltipProps> {
flip={enableFlip}
flipBehavior={flipBehavior}
boundary={boundary}
isVisible={isVisible}
popperOptions={{
modifiers: {
preventOverflow: {
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,78 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`tooltip passes along values to tippy.js 1`] = `
<PopoverBase
animateFill={false}
appendTo={[Function]}
aria="describedby"
arrow={true}
boundary="window"
content={
<div
className=""
role="tooltip"
>
<Unknown>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.
</div>
</Unknown>
</div>
}
delay={
Array [
500,
500,
]
}
distance={15}
duration={
Array [
200,
200,
]
}
flip={true}
flipBehavior={
Array [
"top",
"right",
"bottom",
"left",
"top",
"right",
"bottom",
]
}
isVisible={false}
lazy={true}
maxWidth="18.75rem"
offset={20}
onCreate={[Function]}
performance={true}
placement="top"
popperOptions={
Object {
"modifiers": Object {
"hide": Object {
"enabled": true,
},
"preventOverflow": Object {
"enabled": true,
},
},
}
}
theme="pf-tooltip"
trigger="mouseenter focus"
zIndex={9999}
>
<div>
Tippy Props Test
</div>
</PopoverBase>
`;

exports[`tooltip renders 1`] = `
<PopoverBase
animateFill={false}
Expand Down Expand Up @@ -38,6 +111,7 @@ exports[`tooltip renders 1`] = `
"bottom",
]
}
isVisible={false}
lazy={true}
maxWidth="18.75rem"
onCreate={[Function]}
Expand Down
Loading

Back | FazBrowse Home | New Git URL