Skip to content

Commit 7f18233

Browse files
authored
house popper dependencies, add tippy back as a dep, fix a Tooltip bug (#4565)
* house popper dependencies, add tippy back as a dep, fix a Tooltip bug * cleanup * some snapshots and add license
1 parent 93a8584 commit 7f18233

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3075
-26
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ docs
4242
# Copied types
4343
DeprecatedPopperTypes.ts
4444
DeprecatedTippyTypes.ts
45+
46+
# Copied thirdparty
47+
packages/react-core/src/helpers/Popper/thirdparty/**/*

packages/react-catalog-view-extension/src/components/CatalogTile/__snapshots__/CatalogTile.test.tsx.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ exports[`CatalogTile renders properly 1`] = `
185185
onFocus={[Function]}
186186
onMouseEnter={[Function]}
187187
onMouseLeave={[Function]}
188+
onTriggerEnter={[Function]}
188189
placement="top"
189190
popper={
190191
<div
@@ -467,6 +468,7 @@ exports[`CatalogTile renders properly 1`] = `
467468
onFocus={[Function]}
468469
onMouseEnter={[Function]}
469470
onMouseLeave={[Function]}
471+
onTriggerEnter={[Function]}
470472
placement="top"
471473
popper={
472474
<div
@@ -594,6 +596,7 @@ exports[`CatalogTile renders properly 1`] = `
594596
onFocus={[Function]}
595597
onMouseEnter={[Function]}
596598
onMouseLeave={[Function]}
599+
onTriggerEnter={[Function]}
597600
placement="top"
598601
popper={
599602
<div
@@ -824,6 +827,7 @@ exports[`CatalogTile renders properly 1`] = `
824827
onFocus={[Function]}
825828
onMouseEnter={[Function]}
826829
onMouseLeave={[Function]}
830+
onTriggerEnter={[Function]}
827831
placement="top"
828832
popper={
829833
<div
@@ -1060,6 +1064,7 @@ exports[`CatalogTile renders properly 1`] = `
10601064
onFocus={[Function]}
10611065
onMouseEnter={[Function]}
10621066
onMouseLeave={[Function]}
1067+
onTriggerEnter={[Function]}
10631068
placement="top"
10641069
popper={
10651070
<div

packages/react-core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
"@patternfly/react-icons": "^4.5.0",
3939
"@patternfly/react-styles": "^4.5.0",
4040
"@patternfly/react-tokens": "^4.6.0",
41-
"@popperjs/core": "2.4.2",
4241
"focus-trap": "4.0.2",
4342
"react-dropzone": "9.0.0",
44-
"react-popper": "2.2.3",
43+
"tippy.js": "5.1.2",
4544
"tslib": "^1.11.1"
4645
},
4746
"devDependencies": {

packages/react-core/src/components/Tooltip/Tooltip.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,19 @@ export const Tooltip: React.FunctionComponent<TooltipProps> = ({
132132
const transitionTimerRef = React.useRef(null);
133133
const showTimerRef = React.useRef(null);
134134
const hideTimerRef = React.useRef(null);
135-
const handleKeyDown = (event: KeyboardEvent) => {
135+
const onDocumentKeyDown = (event: KeyboardEvent) => {
136136
if (!triggerManually) {
137137
if (event.keyCode === KEY_CODES.ESCAPE_KEY && visible) {
138138
hide();
139-
} else if (event.keyCode === KEY_CODES.ENTER && !visible) {
139+
}
140+
}
141+
};
142+
const onTriggerEnter = (event: KeyboardEvent) => {
143+
if (event.keyCode === KEY_CODES.ENTER) {
144+
if (!visible) {
140145
show();
146+
} else {
147+
hide();
141148
}
142149
}
143150
};
@@ -241,7 +248,8 @@ export const Tooltip: React.FunctionComponent<TooltipProps> = ({
241248
onFocus={triggerOnFocus && show}
242249
onBlur={triggerOnFocus && hide}
243250
onDocumentClick={triggerOnClick && onDocumentClick}
244-
onDocumentKeyDown={triggerManually ? null : handleKeyDown}
251+
onDocumentKeyDown={triggerManually ? null : onDocumentKeyDown}
252+
onTriggerEnter={triggerManually ? null : onTriggerEnter}
245253
enableFlip={enableFlip}
246254
zIndex={zIndex}
247255
flipBehavior={flipBehavior}

packages/react-core/src/components/Tooltip/__tests__/Generated/__snapshots__/Tooltip.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ exports[`Tooltip should match snapshot (auto-generated) 1`] = `
2323
onFocus={[Function]}
2424
onMouseEnter={[Function]}
2525
onMouseLeave={[Function]}
26+
onTriggerEnter={[Function]}
2627
placement="top"
2728
popper={
2829
<div

packages/react-core/src/components/Tooltip/__tests__/__snapshots__/Tooltip.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ exports[`tooltip renders 1`] = `
2323
onFocus={[Function]}
2424
onMouseEnter={[Function]}
2525
onMouseLeave={[Function]}
26+
onTriggerEnter={[Function]}
2627
placement="top"
2728
popper={
2829
<div

packages/react-core/src/helpers/Popper/Popper.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
33
import { FindRefWrapper } from './FindRefWrapper';
4-
import { usePopper } from 'react-popper';
5-
import { Placement, Modifier, Boundary } from '@popperjs/core';
6-
import { Options as FlipOptions } from '@popperjs/core/lib/modifiers/flip';
7-
import getOppositePlacement from '@popperjs/core/lib/utils/getOppositePlacement';
4+
import { usePopper } from './thirdparty/react-popper/usePopper';
5+
import { Placement, BasePlacement, Modifier } from './thirdparty/popper-core';
86
import { css } from '@patternfly/react-styles';
97

8+
const hash: {
9+
[key: string]: string;
10+
} = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
11+
12+
const getOppositePlacement = (placement: Placement): any =>
13+
placement.replace(/left|right|bottom|top/g, (matched: string) => hash[matched] as BasePlacement);
14+
1015
export interface ToggleMenuBaseProps {
1116
/** The container to append the menu to. Defaults to 'inline'
1217
* If your menu is being cut off you can append it to an element higher up the DOM tree.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# react-popper
2+
Copied and modified from https://github.com/popperjs/react-popper ("react-popper": "2.2.3")
3+
4+
# popper-core
5+
Copied and modified from https://github.com/popperjs/popper-core ("@popperjs/core": "2.4.2")
6+
7+
## Why
8+
Brought this in so that consumers don't have to deal with potential build errors / jest errors, etc
9+
10+
## Note
11+
The code may not have the same level of quality as other components since it is thirdparty code that was modified just enough to make it work with the build. Although some types and eslint issues were fixed, many files have TS errors that were suppressed with the `// @ts-nocheck` comment, and some eslint errors were also supressed with `/* eslint-disable SOMETHING /*` comments.
12+
13+
## Some modifications to make it work with our build
14+
- Converted flow to typescript (using npm package flow-to-ts)
15+
- Fixed some ts linting issues/added eslint ignores and ts-nocheck comments
16+
- Copied in some util functions
17+
- Some source changes
18+
- Replaced some dependencies (import isEqual from 'react-fast-compare' => JSON.stringify)
19+
20+
# Changes for next breaking-change release
21+
- Delete the thirdparty folder and add them as dependencies to the package.json:
22+
`"react-popper": "2.2.3"`
23+
`"@popperjs/core": "2.4.2"`
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Federico Zivolo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @ts-nocheck
2+
/**
3+
* @param parent
4+
* @param child
5+
*/
6+
export default function contains(parent: Element, child: Element) {
7+
// $FlowFixMe: hasOwnProperty doesn't seem to work in tests
8+
const isShadow = Boolean(child.getRootNode && child.getRootNode().host);
9+
10+
// First, attempt with faster native method
11+
if (parent.contains(child)) {
12+
return true;
13+
} // then fallback to custom implementation with Shadow DOM support
14+
else if (isShadow) {
15+
let next = child;
16+
do {
17+
if (next && parent.isSameNode(next)) {
18+
return true;
19+
}
20+
// $FlowFixMe: need a better way to handle this...
21+
next = next.parentNode || next.host;
22+
} while (next);
23+
}
24+
25+
// Give up, the result is false
26+
return false;
27+
}

0 commit comments

Comments
 (0)