@patternfly/react-core 4.168.10 → 4.168.11

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/esm/components/AboutModal/AboutModal.d.ts +2 -0
  3. package/dist/esm/components/AboutModal/AboutModal.d.ts.map +1 -1
  4. package/dist/esm/components/AboutModal/AboutModal.js.map +1 -1
  5. package/dist/esm/components/AboutModal/AboutModalContainer.d.ts +2 -0
  6. package/dist/esm/components/AboutModal/AboutModalContainer.d.ts.map +1 -1
  7. package/dist/esm/components/AboutModal/AboutModalContainer.js +2 -2
  8. package/dist/esm/components/AboutModal/AboutModalContainer.js.map +1 -1
  9. package/dist/esm/components/TextInput/TextInput.d.ts +1 -0
  10. package/dist/esm/components/TextInput/TextInput.d.ts.map +1 -1
  11. package/dist/esm/components/TextInput/TextInput.js +6 -7
  12. package/dist/esm/components/TextInput/TextInput.js.map +1 -1
  13. package/dist/esm/helpers/resizeObserver.d.ts +63 -0
  14. package/dist/esm/helpers/resizeObserver.d.ts.map +1 -0
  15. package/dist/esm/helpers/resizeObserver.js +89 -0
  16. package/dist/esm/helpers/resizeObserver.js.map +1 -0
  17. package/dist/js/components/AboutModal/AboutModal.d.ts +2 -0
  18. package/dist/js/components/AboutModal/AboutModal.d.ts.map +1 -1
  19. package/dist/js/components/AboutModal/AboutModal.js.map +1 -1
  20. package/dist/js/components/AboutModal/AboutModalContainer.d.ts +2 -0
  21. package/dist/js/components/AboutModal/AboutModalContainer.d.ts.map +1 -1
  22. package/dist/js/components/AboutModal/AboutModalContainer.js +2 -2
  23. package/dist/js/components/AboutModal/AboutModalContainer.js.map +1 -1
  24. package/dist/js/components/TextInput/TextInput.d.ts +1 -0
  25. package/dist/js/components/TextInput/TextInput.d.ts.map +1 -1
  26. package/dist/js/components/TextInput/TextInput.js +5 -6
  27. package/dist/js/components/TextInput/TextInput.js.map +1 -1
  28. package/dist/js/helpers/resizeObserver.d.ts +63 -0
  29. package/dist/js/helpers/resizeObserver.d.ts.map +1 -0
  30. package/dist/js/helpers/resizeObserver.js +93 -0
  31. package/dist/js/helpers/resizeObserver.js.map +1 -0
  32. package/dist/umd/react-core.js +94 -8
  33. package/dist/umd/react-core.min.js +3 -3
  34. package/package.json +5 -5
  35. package/src/components/AboutModal/AboutModal.tsx +2 -0
  36. package/src/components/AboutModal/AboutModalContainer.tsx +8 -1
  37. package/src/components/TextInput/TextInput.tsx +6 -7
  38. package/src/helpers/resizeObserver.tsx +91 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.168.10",
3
+ "version": "4.168.11",
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.19.10",
38
- "@patternfly/react-styles": "^4.18.10",
39
- "@patternfly/react-tokens": "^4.20.10",
37
+ "@patternfly/react-icons": "^4.19.11",
38
+ "@patternfly/react-styles": "^4.18.11",
39
+ "@patternfly/react-tokens": "^4.20.11",
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": "67e19e6066f3587428f52544ae00beb89827adc5"
63
+ "gitHead": "003f43487f9256128b7dcc45ee6f343f9e8ac7ec"
64
64
  }
@@ -32,6 +32,8 @@ export interface AboutModalProps {
32
32
  appendTo?: HTMLElement | (() => HTMLElement);
33
33
  /** Set aria label to the close button */
34
34
  closeButtonAriaLabel?: string;
35
+ /** Flag to disable focus trap */
36
+ disableFocusTrap?: boolean;
35
37
  }
36
38
 
37
39
  interface ModalState {
@@ -36,6 +36,8 @@ export interface AboutModalContainerProps extends React.HTMLProps<HTMLDivElement
36
36
  aboutModalBoxContentId: string;
37
37
  /** Set close button aria label */
38
38
  closeButtonAriaLabel?: string;
39
+ /** Flag to disable focus trap */
40
+ disableFocusTrap?: boolean;
39
41
  }
40
42
 
41
43
  export const AboutModalContainer: React.FunctionComponent<AboutModalContainerProps> = ({
@@ -51,6 +53,7 @@ export const AboutModalContainer: React.FunctionComponent<AboutModalContainerPro
51
53
  closeButtonAriaLabel,
52
54
  aboutModalBoxHeaderId,
53
55
  aboutModalBoxContentId,
56
+ disableFocusTrap = false,
54
57
  ...props
55
58
  }: AboutModalContainerProps) => {
56
59
  if (!isOpen) {
@@ -58,7 +61,11 @@ export const AboutModalContainer: React.FunctionComponent<AboutModalContainerPro
58
61
  }
59
62
  return (
60
63
  <Backdrop>
61
- <FocusTrap focusTrapOptions={{ clickOutsideDeactivates: true }} className={css(styles.bullseye)}>
64
+ <FocusTrap
65
+ active={!disableFocusTrap}
66
+ focusTrapOptions={{ clickOutsideDeactivates: true }}
67
+ className={css(styles.bullseye)}
68
+ >
62
69
  <AboutModalBox
63
70
  className={className}
64
71
  aria-labelledby={aboutModalBoxHeaderId}
@@ -2,8 +2,9 @@ import * as React from 'react';
2
2
  import styles from '@patternfly/react-styles/css/components/FormControl/form-control';
3
3
  import { css } from '@patternfly/react-styles';
4
4
  import { ValidatedOptions } from '../../helpers/constants';
5
- import { debounce, trimLeft, canUseDOM } from '../../helpers/util';
5
+ import { trimLeft } from '../../helpers/util';
6
6
  import { getDefaultOUIAId, getOUIAProps, OUIAProps } from '../../helpers';
7
+ import { getResizeObserver } from '../../helpers/resizeObserver';
7
8
 
8
9
  export enum TextInputTypes {
9
10
  text = 'text',
@@ -89,6 +90,7 @@ export class TextInputBase extends React.Component<TextInputProps, TextInputStat
89
90
  ouiaSafe: true
90
91
  };
91
92
  inputRef = React.createRef<HTMLInputElement>();
93
+ observer: any = () => {};
92
94
 
93
95
  constructor(props: TextInputProps) {
94
96
  super(props);
@@ -109,18 +111,15 @@ export class TextInputBase extends React.Component<TextInputProps, TextInputStat
109
111
 
110
112
  componentDidMount() {
111
113
  if (this.props.isLeftTruncated) {
114
+ const inputRef = this.props.innerRef || this.inputRef;
115
+ this.observer = getResizeObserver(inputRef.current, this.handleResize);
112
116
  this.handleResize();
113
- if (canUseDOM) {
114
- window.addEventListener('resize', debounce(this.handleResize, 250));
115
- }
116
117
  }
117
118
  }
118
119
 
119
120
  componentWillUnmount() {
120
121
  if (this.props.isLeftTruncated) {
121
- if (canUseDOM) {
122
- window.removeEventListener('resize', debounce(this.handleResize, 250));
123
- }
122
+ this.observer();
124
123
  }
125
124
  }
126
125
 
@@ -0,0 +1,91 @@
1
+ import * as React from 'react';
2
+ import { canUseDOM } from './util';
3
+
4
+ /**
5
+ * This function creates a ResizeObserver used to handle resize events for the given containerRef. If ResizeObserver
6
+ * or the given containerRef are not available, a window resize event listener is used by default.
7
+ *
8
+ * Example 1:
9
+ *
10
+ * private containerRef = React.createRef<HTMLDivElement>();
11
+ * private observer: any = () => {};
12
+ *
13
+ * public componentDidMount() {
14
+ * this.observer = getResizeObserver(this.containerRef.current, this.handleResize);
15
+ * }
16
+ *
17
+ * public componentWillUnmount() {
18
+ * this.observer();
19
+ * }
20
+ *
21
+ * private handleResize = () => {
22
+ * if (this.containerRef.current && this.containerRef.current.clientWidth) {
23
+ * this.setState({ width: this.containerRef.current.clientWidth });
24
+ * }
25
+ * };
26
+ *
27
+ * public render() {
28
+ * return (
29
+ * <div ref={this.containerRef} >
30
+ * <Chart width={this.state.width} ... />
31
+ * </div>
32
+ * );
33
+ * }
34
+ *
35
+ * Example 2:
36
+ *
37
+ * private inputRef = React.createRef<HTMLInputElement>();
38
+ * private observer: any = () => {};
39
+ *
40
+ * public componentDidMount() {
41
+ * this.observer = getResizeObserver(this.inputRef.current, this.handleResize);
42
+ * }
43
+ *
44
+ * public componentWillUnmount() {
45
+ * this.observer();
46
+ * }
47
+ *
48
+ * private handleResize = () => {
49
+ * if (this.inputRef.current) {
50
+ * trimLeft(inputRef.current, String(this.props.value));
51
+ * }
52
+ * };
53
+ *
54
+ * public render() {
55
+ * return (
56
+ * <input ref={this.inputRef} ... />
57
+ * );
58
+ * }
59
+ *
60
+ * @param {React.RefObject} containerRef The container reference to observe
61
+ * @param {Function} handleResize The function to call for resize events
62
+ * @return {Function} The function used to unobserve resize events
63
+ */
64
+ export const getResizeObserver = (containerRef: React.RefObject<any>, handleResize: () => void) => {
65
+ let unobserve: any;
66
+
67
+ if (canUseDOM) {
68
+ const { ResizeObserver } = window as any;
69
+
70
+ if (containerRef && ResizeObserver) {
71
+ const resizeObserver = new ResizeObserver((entries: any) => {
72
+ // Wrap resize function in requestAnimationFrame to avoid "ResizeObserver loop limit exceeded" errors
73
+ window.requestAnimationFrame(() => {
74
+ if (Array.isArray(entries) && entries.length > 0) {
75
+ handleResize();
76
+ }
77
+ });
78
+ });
79
+ resizeObserver.observe(containerRef);
80
+ unobserve = () => resizeObserver.unobserve(containerRef);
81
+ } else {
82
+ window.addEventListener('resize', handleResize);
83
+ unobserve = () => window.removeEventListener('resize', handleResize);
84
+ }
85
+ }
86
+ return () => {
87
+ if (unobserve) {
88
+ unobserve();
89
+ }
90
+ };
91
+ };