Skip to content

Commit 73f46a7

Browse files
sjolicoeurpivotal
authored andcommitted
feat(Tooltip): 8pt Tooltips: Hover behavior
8pt Tooltips: Hover now has the option to be sticky as to offer a wider hover area for the user. [Finishes #138673781] Signed-off-by: Anushka Makhija <amakhija@pivotal.io>
1 parent c44f9b7 commit 73f46a7

File tree

5 files changed

+81
-15
lines changed

5 files changed

+81
-15
lines changed

library/spec/pivotal-ui-react/tooltip/tooltip_spec.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import '../spec_helper'
2-
;
2+
;
33
import {Tooltip} from 'pui-react-tooltip';
44

55
describe('Tooltip Component', () => {
6-
const renderComponent = props => ReactTestUtils.renderIntoDocument(<Tooltip {...props}>Some default tooltip</Tooltip>);
6+
const renderComponent = props => ReactTestUtils.renderIntoDocument(<Tooltip {...props}>Some default
7+
tooltip</Tooltip>);
78

89
it('renders', () => {
910
const result = renderComponent();
@@ -70,4 +71,36 @@ describe('Tooltip Component', () => {
7071
expect(content).toHaveClass('tooltip-lg');
7172
});
7273
});
73-
});
74+
75+
describe('sticky', () => {
76+
let renderComponent;
77+
beforeEach(() => {
78+
renderComponent = props => ReactTestUtils.renderIntoDocument(<Tooltip {...props}>Some default tooltip</Tooltip>);
79+
});
80+
81+
describe('is not set', () => {
82+
it('does not render with the hoverable class', () => {
83+
const result = renderComponent({isSticky: false});
84+
const content = ReactTestUtils.findRenderedDOMComponentWithClass(result, 'tooltip-container');
85+
expect(content).not.toHaveClass('tooltip-hoverable');
86+
});
87+
});
88+
89+
describe('is set to false', () => {
90+
it('does not render with the hoverable class', () => {
91+
const result = renderComponent({isSticky: false});
92+
const content = ReactTestUtils.findRenderedDOMComponentWithClass(result, 'tooltip-container');
93+
expect(content).not.toHaveClass('tooltip-hoverable');
94+
});
95+
});
96+
97+
describe('is set to true', () => {
98+
it('renders with the hoverable class', () => {
99+
const result = renderComponent({isSticky: true});
100+
const content = ReactTestUtils.findRenderedDOMComponentWithClass(result, 'tooltip-container');
101+
expect(content).toHaveClass('tooltip-hoverable');
102+
});
103+
});
104+
});
105+
})
106+
;

library/spec/pivotal-ui-react/tooltip/tooltip_trigger_spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,12 @@ describe('TooltipTrigger Component', () => {
164164
expect(tooltip).toHaveClass('tooltip-container-hidden');
165165
});
166166
});
167+
168+
describe('isSticky', () => {
169+
it('renders the tooltip with the "isSticky" prop', () => {
170+
const result = renderComponent({isSticky: true, tooltip: 'Some tooltip content'});
171+
const content = ReactTestUtils.findRenderedDOMComponentWithClass(result, 'tooltip-container');
172+
expect(content).toHaveClass('tooltip-hoverable');
173+
});
174+
});
167175
});

library/src/pivotal-ui-react/tooltip/tooltip.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,26 @@ import classnames from 'classnames';
66
export class Tooltip extends React.Component {
77
static propTypes = {
88
visible: PropTypes.bool,
9-
size: PropTypes.oneOf(['auto','sm', 'md', 'lg'])
9+
size: PropTypes.oneOf(['auto','sm', 'md', 'lg']),
10+
isSticky: PropTypes.bool
1011
}
1112

1213
static defaultProps = {
1314
visible: true,
14-
size: 'auto'
15+
size: 'auto',
16+
isSticky: false
1517
}
1618

1719
constructor(props) {
1820
super(props);
1921
}
2022

2123
render() {
22-
let {visible, size, className, children, ...others} = this.props;
24+
let {isSticky, visible, size, className, children, ...others} = this.props;
2325

2426
const newClasses = classnames('tooltip-container', visible ? 'tooltip-container-visible' : 'tooltip-container-hidden',
2527
size === 'auto' ? null : `tooltip-${size}`,
28+
isSticky? 'tooltip-hoverable': null,
2629
className);
2730

2831
return (
@@ -42,7 +45,8 @@ export class TooltipTrigger extends React.Component {
4245
onEntered: PropTypes.func,
4346
onExited: PropTypes.func,
4447
theme: PropTypes.oneOf(['dark', 'light']),
45-
size: PropTypes.oneOf(['auto', 'sm', 'md', 'lg'])
48+
size: PropTypes.oneOf(['auto', 'sm', 'md', 'lg']),
49+
isSticky: PropTypes.bool
4650
}
4751

4852
static defaultProps = {
@@ -52,7 +56,8 @@ export class TooltipTrigger extends React.Component {
5256
onEntered: () => {},
5357
onExited: () => {},
5458
theme: 'dark',
55-
size: 'auto'
59+
size: 'auto',
60+
isSticky: false
5661
}
5762

5863
constructor(props) {
@@ -80,7 +85,7 @@ export class TooltipTrigger extends React.Component {
8085
}
8186

8287
render() {
83-
const {placement, tooltip, trigger, className, clickHideDelay, onEntered, onExited, theme, size, ...others} = this.props;
88+
const {isSticky, placement, tooltip, trigger, className, clickHideDelay, onEntered, onExited, theme, size, ...others} = this.props;
8489
const {visible} = this.state;
8590

8691
let placementClass;
@@ -108,7 +113,7 @@ export class TooltipTrigger extends React.Component {
108113
return (
109114
<div {...newProps}>
110115
{this.props.children}
111-
<Tooltip size={this.props.size} visible={visible}>{tooltip}</Tooltip>
116+
<Tooltip {...{isSticky, size: this.props.size, visible}}>{tooltip}</Tooltip>
112117
</div>
113118
);
114119
}

library/src/pivotal-ui/components/tooltips/tooltips.scss

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99

1010
.tooltip-container {
1111
//Hover Effect for HTML & CSS ONLY
12-
13-
&.tooltip-container-visible {
14-
visibility: visible;
15-
}
16-
1712
visibility: hidden;
1813
transition: opacity $tooltip-opacity-transition;
1914
z-index: $tooltip-container-z;
@@ -24,6 +19,22 @@
2419
margin: 0 0 $tooltip-margin 0; //space for the triangle indicator
2520
text-align: left;
2621

22+
&.tooltip-container-visible {
23+
visibility: visible;
24+
}
25+
26+
&.tooltip-hoverable {
27+
&:after {
28+
content:"";
29+
position: absolute;
30+
width:calc(100% + 16px);
31+
height:calc(100% + 16px);
32+
top:50%;
33+
left:50%;
34+
transform: translateX(-50%) translateY(-50%);
35+
}
36+
}
37+
2738
.tooltip-content {
2839
white-space: nowrap;
2940
padding: $tooltip-padding;

styleguide/docs/react/tooltip.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Property | Required | Type | Default
2525
---------------|----------|-------------------------------------------|----------|----------------------------------
2626
visible | no | Boolean | true | Whether the tooltip contents are visible
2727
size | no | oneOf(['auto', 'sm', 'md', 'lg']) | auto | Size of the tooltip
28+
isSticky | no | Boolean | false | Whether the tooltip hover is sticky or not
2829
2930
* See [React proptype definitions here](https://facebook.github.io/react/docs/typechecking-with-proptypes.html)
3031
@@ -67,6 +68,7 @@ pin | no | Boolean | true |
6768
placement | no | oneOf('top', 'bottom', 'left', 'right') | 'right' | Placement of overlay in relation to target
6869
theme | no | oneOf(['light', 'dark']) | dark | Theme of tooltip background and text
6970
trigger | no | oneOf('hover', 'click', 'focus', 'manual') | 'hover' | Action to trigger showing overlay
71+
isSticky | no | Boolean | false | Whether the tooltip hover is sticky or not
7072
7173
## Basic usage
7274
@@ -143,6 +145,8 @@ onEntered | no | Func | () => {}
143145
onExited | no | Func | () => {} | Callback that is called after the tooltip is hidden
144146
theme | no | oneOf(['light', 'dark']) | dark | Theme of tooltip background and text
145147
size | no | oneOf(['auto', 'sm', 'md', 'lg']) | auto | Size of the tooltip
148+
isSticky | no | Boolean | false | Whether the tooltip hover is sticky or not
149+
146150
147151
* See [React proptype definitions here](https://facebook.github.io/react/docs/typechecking-with-proptypes.html)
148152
@@ -170,6 +174,11 @@ the TooltipTrigger will add a lot of markup to the DOM if you are using it in a
170174
<button className="btn btn-default">Click me</button>
171175
</TooltipTrigger>
172176
</div>
177+
<div className="form-group form-inline">
178+
<TooltipTrigger tooltip="Some tooltip" isSticky={true} placement="right">
179+
<button className="btn btn-default">Hover over me too!</button>
180+
</TooltipTrigger>
181+
</div>
173182
</div>
174183
```
175184

0 commit comments

Comments
 (0)