@patternfly/react-core 4.189.4 → 4.189.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.189.4",
3
+ "version": "4.189.5",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -34,9 +34,9 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.40.4",
38
- "@patternfly/react-styles": "^4.39.4",
39
- "@patternfly/react-tokens": "^4.41.4",
37
+ "@patternfly/react-icons": "^4.40.5",
38
+ "@patternfly/react-styles": "^4.39.5",
39
+ "@patternfly/react-tokens": "^4.41.5",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "63c9e1d1da66ac8b1e4a47fa6e76e530cc98208f"
63
+ "gitHead": "01c8b913108c70fcddb6ee6d7bdf523dffc620b7"
64
64
  }
@@ -129,6 +129,8 @@ export class Tabs extends React.Component<TabsProps, TabsState> {
129
129
  }
130
130
  }
131
131
 
132
+ scrollTimeout: NodeJS.Timeout = null;
133
+
132
134
  static defaultProps: PickOptional<TabsProps> = {
133
135
  activeKey: 0,
134
136
  onSelect: () => undefined as any,
@@ -182,28 +184,32 @@ export class Tabs extends React.Component<TabsProps, TabsState> {
182
184
  }
183
185
 
184
186
  handleScrollButtons = () => {
185
- const container = this.tabList.current;
186
- let disableLeftScrollButton = true;
187
- let disableRightScrollButton = true;
188
- let showScrollButtons = false;
187
+ // add debounce to the scroll event
188
+ clearTimeout(this.scrollTimeout);
189
+ this.scrollTimeout = setTimeout(() => {
190
+ const container = this.tabList.current;
191
+ let disableLeftScrollButton = true;
192
+ let disableRightScrollButton = true;
193
+ let showScrollButtons = false;
189
194
 
190
- if (container && !this.props.isVertical) {
191
- // get first element and check if it is in view
192
- const overflowOnLeft = !isElementInView(container, container.firstChild as HTMLElement, false);
195
+ if (container && !this.props.isVertical) {
196
+ // get first element and check if it is in view
197
+ const overflowOnLeft = !isElementInView(container, container.firstChild as HTMLElement, false);
193
198
 
194
- // get last element and check if it is in view
195
- const overflowOnRight = !isElementInView(container, container.lastChild as HTMLElement, false);
199
+ // get last element and check if it is in view
200
+ const overflowOnRight = !isElementInView(container, container.lastChild as HTMLElement, false);
196
201
 
197
- showScrollButtons = overflowOnLeft || overflowOnRight;
202
+ showScrollButtons = overflowOnLeft || overflowOnRight;
198
203
 
199
- disableLeftScrollButton = !overflowOnLeft;
200
- disableRightScrollButton = !overflowOnRight;
201
- }
202
- this.setState({
203
- showScrollButtons,
204
- disableLeftScrollButton,
205
- disableRightScrollButton
206
- });
204
+ disableLeftScrollButton = !overflowOnLeft;
205
+ disableRightScrollButton = !overflowOnRight;
206
+ }
207
+ this.setState({
208
+ showScrollButtons,
209
+ disableLeftScrollButton,
210
+ disableRightScrollButton
211
+ });
212
+ }, 100);
207
213
  };
208
214
 
209
215
  scrollLeft = () => {
@@ -261,6 +267,7 @@ export class Tabs extends React.Component<TabsProps, TabsState> {
261
267
  window.removeEventListener('resize', this.handleScrollButtons, false);
262
268
  }
263
269
  }
270
+ clearTimeout(this.scrollTimeout);
264
271
  }
265
272
 
266
273
  componentDidUpdate(prevProps: TabsProps) {
@@ -39,24 +39,30 @@ export function debounce(this: any, func: (...args: any[]) => any, wait: number)
39
39
  * @param {HTMLElement} container The container to check if the element is in view of.
40
40
  * @param {HTMLElement} element The element to check if it is view
41
41
  * @param {boolean} partial true if partial view is allowed
42
+ * @param {boolean} strict true if strict mode is set, never consider the container width and element width
42
43
  *
43
44
  * @returns { boolean } True if the component is in View.
44
45
  */
45
- export function isElementInView(container: HTMLElement, element: HTMLElement, partial: boolean) {
46
+ export function isElementInView(
47
+ container: HTMLElement,
48
+ element: HTMLElement,
49
+ partial: boolean,
50
+ strict: boolean = false
51
+ ): boolean {
46
52
  if (!container || !element) {
47
53
  return false;
48
54
  }
49
55
  const containerBounds = container.getBoundingClientRect();
50
56
  const elementBounds = element.getBoundingClientRect();
51
- const containerBoundsLeft = Math.floor(containerBounds.left);
57
+ const containerBoundsLeft = Math.ceil(containerBounds.left);
52
58
  const containerBoundsRight = Math.floor(containerBounds.right);
53
- const elementBoundsLeft = Math.floor(elementBounds.left);
59
+ const elementBoundsLeft = Math.ceil(elementBounds.left);
54
60
  const elementBoundsRight = Math.floor(elementBounds.right);
55
61
 
56
62
  // Check if in view
57
63
  const isTotallyInView = elementBoundsLeft >= containerBoundsLeft && elementBoundsRight <= containerBoundsRight;
58
64
  const isPartiallyInView =
59
- partial &&
65
+ (partial || (!strict && containerBounds.width < elementBounds.width)) &&
60
66
  ((elementBoundsLeft < containerBoundsLeft && elementBoundsRight > containerBoundsLeft) ||
61
67
  (elementBoundsRight > containerBoundsRight && elementBoundsLeft < containerBoundsRight));
62
68