carbon-react 105.0.1 → 105.0.2

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.
@@ -16,7 +16,7 @@ declare namespace Popover {
16
16
  const modifiers: PropTypes.Requireable<any[]>;
17
17
  const onFirstUpdate: PropTypes.Requireable<(...args: any[]) => any>;
18
18
  const disablePortal: PropTypes.Requireable<boolean>;
19
- const reference: PropTypes.Requireable<PropTypes.InferProps<{
19
+ const reference: PropTypes.Validator<PropTypes.InferProps<{
20
20
  current: PropTypes.Requireable<any>;
21
21
  }>>;
22
22
  }
@@ -1,10 +1,11 @@
1
- import React, { useEffect, useLayoutEffect, useRef } from "react";
1
+ import React, { useContext, useEffect, useLayoutEffect, useRef } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import PropTypes from "prop-types";
4
4
  import { createPopper } from "@popperjs/core";
5
5
  import useResizeObserver from "../../hooks/__internal__/useResizeObserver";
6
6
  import StyledBackdrop from "./popover.style";
7
7
  import CarbonScopedTokensProvider from "../../style/design-tokens/carbon-scoped-tokens-provider/carbon-scoped-tokens-provider.component";
8
+ import { ModalContext } from "../../components/modal/modal.component";
8
9
 
9
10
  const Popover = ({
10
11
  children,
@@ -16,10 +17,18 @@ const Popover = ({
16
17
  disableBackgroundUI
17
18
  }) => {
18
19
  const elementDOM = useRef();
20
+ const {
21
+ isInModal
22
+ } = useContext(ModalContext);
23
+ let mountNode = document.body;
24
+
25
+ if (isInModal && reference.current) {
26
+ mountNode = reference.current.closest("[role='dialog']");
27
+ }
19
28
 
20
29
  if (!elementDOM.current && !disablePortal) {
21
30
  elementDOM.current = document.createElement("div");
22
- document.body.appendChild(elementDOM.current);
31
+ mountNode.appendChild(elementDOM.current);
23
32
  }
24
33
 
25
34
  const popperInstance = useRef();
@@ -68,10 +77,11 @@ const Popover = ({
68
77
  useEffect(() => {
69
78
  return () => {
70
79
  if (!disablePortal) {
71
- document.body.removeChild(elementDOM.current);
80
+ mountNode.removeChild(elementDOM.current);
81
+ elementDOM.current = null;
72
82
  }
73
83
  };
74
- }, [disablePortal]);
84
+ }, [disablePortal, mountNode]);
75
85
 
76
86
  if (disableBackgroundUI) {
77
87
  content = /*#__PURE__*/React.createElement(StyledBackdrop, null, content);
@@ -102,6 +112,6 @@ Popover.propTypes = {
102
112
  // Reference element, children will be positioned in relation to this element - should be a ref
103
113
  reference: PropTypes.shape({
104
114
  current: PropTypes.any
105
- })
115
+ }).isRequired
106
116
  };
107
117
  export default Popover;
@@ -140,7 +140,8 @@ const Modal = ({
140
140
  }, /*#__PURE__*/React.createElement(ModalContext.Provider, {
141
141
  value: {
142
142
  isAnimationComplete,
143
- triggerRefocusFlag
143
+ triggerRefocusFlag,
144
+ isInModal: true
144
145
  }
145
146
  }, content)))));
146
147
  };
@@ -1,11 +1,9 @@
1
1
  export default SelectText;
2
- declare function SelectText({ disabled, formattedValue, onClick, onKeyDown, onFocus, onBlur, onMouseDown, placeholder, readOnly, textId, transparent, }: {
2
+ declare function SelectText({ disabled, formattedValue, onClick, onKeyDown, onMouseDown, placeholder, readOnly, textId, transparent, }: {
3
3
  disabled: any;
4
4
  formattedValue?: string | undefined;
5
5
  onClick: any;
6
6
  onKeyDown: any;
7
- onFocus: any;
8
- onBlur: any;
9
7
  onMouseDown: any;
10
8
  placeholder: any;
11
9
  readOnly: any;
@@ -16,9 +14,7 @@ declare namespace SelectText {
16
14
  namespace propTypes {
17
15
  const disabled: PropTypes.Requireable<boolean>;
18
16
  const formattedValue: PropTypes.Requireable<string>;
19
- const onBlur: PropTypes.Requireable<(...args: any[]) => any>;
20
17
  const onClick: PropTypes.Requireable<(...args: any[]) => any>;
21
- const onFocus: PropTypes.Requireable<(...args: any[]) => any>;
22
18
  const onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
23
19
  const onMouseDown: PropTypes.Requireable<(...args: any[]) => any>;
24
20
  const placeholder: PropTypes.Requireable<string>;
@@ -1,38 +1,22 @@
1
- import React, { useContext } from "react";
1
+ import React from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import StyledSelectText from "./select-text.style";
4
- import { InputContext } from "../../../../__internal__/input-behaviour";
5
4
 
6
5
  const SelectText = ({
7
6
  disabled,
8
7
  formattedValue = "",
9
8
  onClick,
10
9
  onKeyDown,
11
- onFocus,
12
- onBlur,
13
10
  onMouseDown,
14
11
  placeholder,
15
12
  readOnly,
16
13
  textId,
17
14
  transparent
18
15
  }) => {
19
- const inputContext = useContext(InputContext);
20
16
  const hasPlaceholder = !disabled && !readOnly && !formattedValue;
21
17
 
22
- function handleFocus(event) {
23
- inputContext.onFocus(event);
24
-
25
- if (onFocus) {
26
- onFocus(event);
27
- }
28
- }
29
-
30
- function handleBlur(event) {
31
- inputContext.onBlur(event);
32
-
33
- if (onBlur) {
34
- onBlur(event);
35
- }
18
+ function handleClick(event) {
19
+ onClick(event);
36
20
  }
37
21
 
38
22
  return /*#__PURE__*/React.createElement(StyledSelectText, {
@@ -41,9 +25,7 @@ const SelectText = ({
41
25
  disabled: disabled,
42
26
  hasPlaceholder: hasPlaceholder,
43
27
  id: textId,
44
- onBlur: handleBlur,
45
- onClick: onClick,
46
- onFocus: handleFocus,
28
+ onClick: handleClick,
47
29
  onKeyDown: onKeyDown,
48
30
  onMouseDown: onMouseDown,
49
31
  readOnly: readOnly,
@@ -60,15 +42,9 @@ SelectText.propTypes = {
60
42
  /** Value to be displayed */
61
43
  formattedValue: PropTypes.string,
62
44
 
63
- /** Callback function for when the Select Textbox loses it's focus. */
64
- onBlur: PropTypes.func,
65
-
66
45
  /** Callback function for when the component is clicked. */
67
46
  onClick: PropTypes.func,
68
47
 
69
- /** Callback function for when the Select Textbox is focused. */
70
- onFocus: PropTypes.func,
71
-
72
48
  /** Callback function for when the key is pressed when focused on Select Text. */
73
49
  onKeyDown: PropTypes.func,
74
50
 
@@ -150,8 +150,11 @@ const SelectTextbox = ({
150
150
  textId: textId.current,
151
151
  transparent: transparent,
152
152
  onKeyDown: handleSelectTextKeydown,
153
- placeholder: placeholder || l.select.placeholder()
154
- }, getTextboxProps()));
153
+ placeholder: placeholder || l.select.placeholder(),
154
+ onClick: handleTextboxClick,
155
+ disabled: disabled,
156
+ readOnly: readOnly
157
+ }, restProps));
155
158
  }
156
159
 
157
160
  function handleSelectTextKeydown(event) {
@@ -16,7 +16,7 @@ declare namespace Popover {
16
16
  const modifiers: PropTypes.Requireable<any[]>;
17
17
  const onFirstUpdate: PropTypes.Requireable<(...args: any[]) => any>;
18
18
  const disablePortal: PropTypes.Requireable<boolean>;
19
- const reference: PropTypes.Requireable<PropTypes.InferProps<{
19
+ const reference: PropTypes.Validator<PropTypes.InferProps<{
20
20
  current: PropTypes.Requireable<any>;
21
21
  }>>;
22
22
  }
@@ -19,6 +19,8 @@ var _popover = _interopRequireDefault(require("./popover.style"));
19
19
 
20
20
  var _carbonScopedTokensProvider = _interopRequireDefault(require("../../style/design-tokens/carbon-scoped-tokens-provider/carbon-scoped-tokens-provider.component"));
21
21
 
22
+ var _modal = require("../../components/modal/modal.component");
23
+
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
25
 
24
26
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
@@ -35,10 +37,18 @@ const Popover = ({
35
37
  disableBackgroundUI
36
38
  }) => {
37
39
  const elementDOM = (0, _react.useRef)();
40
+ const {
41
+ isInModal
42
+ } = (0, _react.useContext)(_modal.ModalContext);
43
+ let mountNode = document.body;
44
+
45
+ if (isInModal && reference.current) {
46
+ mountNode = reference.current.closest("[role='dialog']");
47
+ }
38
48
 
39
49
  if (!elementDOM.current && !disablePortal) {
40
50
  elementDOM.current = document.createElement("div");
41
- document.body.appendChild(elementDOM.current);
51
+ mountNode.appendChild(elementDOM.current);
42
52
  }
43
53
 
44
54
  const popperInstance = (0, _react.useRef)();
@@ -88,10 +98,11 @@ const Popover = ({
88
98
  (0, _react.useEffect)(() => {
89
99
  return () => {
90
100
  if (!disablePortal) {
91
- document.body.removeChild(elementDOM.current);
101
+ mountNode.removeChild(elementDOM.current);
102
+ elementDOM.current = null;
92
103
  }
93
104
  };
94
- }, [disablePortal]);
105
+ }, [disablePortal, mountNode]);
95
106
 
96
107
  if (disableBackgroundUI) {
97
108
  content = /*#__PURE__*/_react.default.createElement(_popover.default, null, content);
@@ -122,7 +133,7 @@ Popover.propTypes = {
122
133
  // Reference element, children will be positioned in relation to this element - should be a ref
123
134
  reference: _propTypes.default.shape({
124
135
  current: _propTypes.default.any
125
- })
136
+ }).isRequired
126
137
  };
127
138
  var _default = Popover;
128
139
  exports.default = _default;
@@ -165,7 +165,8 @@ const Modal = ({
165
165
  }, /*#__PURE__*/_react.default.createElement(ModalContext.Provider, {
166
166
  value: {
167
167
  isAnimationComplete,
168
- triggerRefocusFlag
168
+ triggerRefocusFlag,
169
+ isInModal: true
169
170
  }
170
171
  }, content)))));
171
172
  };
@@ -1,11 +1,9 @@
1
1
  export default SelectText;
2
- declare function SelectText({ disabled, formattedValue, onClick, onKeyDown, onFocus, onBlur, onMouseDown, placeholder, readOnly, textId, transparent, }: {
2
+ declare function SelectText({ disabled, formattedValue, onClick, onKeyDown, onMouseDown, placeholder, readOnly, textId, transparent, }: {
3
3
  disabled: any;
4
4
  formattedValue?: string | undefined;
5
5
  onClick: any;
6
6
  onKeyDown: any;
7
- onFocus: any;
8
- onBlur: any;
9
7
  onMouseDown: any;
10
8
  placeholder: any;
11
9
  readOnly: any;
@@ -16,9 +14,7 @@ declare namespace SelectText {
16
14
  namespace propTypes {
17
15
  const disabled: PropTypes.Requireable<boolean>;
18
16
  const formattedValue: PropTypes.Requireable<string>;
19
- const onBlur: PropTypes.Requireable<(...args: any[]) => any>;
20
17
  const onClick: PropTypes.Requireable<(...args: any[]) => any>;
21
- const onFocus: PropTypes.Requireable<(...args: any[]) => any>;
22
18
  const onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
23
19
  const onMouseDown: PropTypes.Requireable<(...args: any[]) => any>;
24
20
  const placeholder: PropTypes.Requireable<string>;
@@ -5,50 +5,29 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _react = _interopRequireWildcard(require("react"));
8
+ var _react = _interopRequireDefault(require("react"));
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _selectText = _interopRequireDefault(require("./select-text.style"));
13
13
 
14
- var _inputBehaviour = require("../../../../__internal__/input-behaviour");
15
-
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
18
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
19
-
20
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
16
  const SelectText = ({
23
17
  disabled,
24
18
  formattedValue = "",
25
19
  onClick,
26
20
  onKeyDown,
27
- onFocus,
28
- onBlur,
29
21
  onMouseDown,
30
22
  placeholder,
31
23
  readOnly,
32
24
  textId,
33
25
  transparent
34
26
  }) => {
35
- const inputContext = (0, _react.useContext)(_inputBehaviour.InputContext);
36
27
  const hasPlaceholder = !disabled && !readOnly && !formattedValue;
37
28
 
38
- function handleFocus(event) {
39
- inputContext.onFocus(event);
40
-
41
- if (onFocus) {
42
- onFocus(event);
43
- }
44
- }
45
-
46
- function handleBlur(event) {
47
- inputContext.onBlur(event);
48
-
49
- if (onBlur) {
50
- onBlur(event);
51
- }
29
+ function handleClick(event) {
30
+ onClick(event);
52
31
  }
53
32
 
54
33
  return /*#__PURE__*/_react.default.createElement(_selectText.default, {
@@ -57,9 +36,7 @@ const SelectText = ({
57
36
  disabled: disabled,
58
37
  hasPlaceholder: hasPlaceholder,
59
38
  id: textId,
60
- onBlur: handleBlur,
61
- onClick: onClick,
62
- onFocus: handleFocus,
39
+ onClick: handleClick,
63
40
  onKeyDown: onKeyDown,
64
41
  onMouseDown: onMouseDown,
65
42
  readOnly: readOnly,
@@ -76,15 +53,9 @@ SelectText.propTypes = {
76
53
  /** Value to be displayed */
77
54
  formattedValue: _propTypes.default.string,
78
55
 
79
- /** Callback function for when the Select Textbox loses it's focus. */
80
- onBlur: _propTypes.default.func,
81
-
82
56
  /** Callback function for when the component is clicked. */
83
57
  onClick: _propTypes.default.func,
84
58
 
85
- /** Callback function for when the Select Textbox is focused. */
86
- onFocus: _propTypes.default.func,
87
-
88
59
  /** Callback function for when the key is pressed when focused on Select Text. */
89
60
  onKeyDown: _propTypes.default.func,
90
61
 
@@ -171,8 +171,11 @@ const SelectTextbox = ({
171
171
  textId: textId.current,
172
172
  transparent: transparent,
173
173
  onKeyDown: handleSelectTextKeydown,
174
- placeholder: placeholder || l.select.placeholder()
175
- }, getTextboxProps()));
174
+ placeholder: placeholder || l.select.placeholder(),
175
+ onClick: handleTextboxClick,
176
+ disabled: disabled,
177
+ readOnly: readOnly
178
+ }, restProps));
176
179
  }
177
180
 
178
181
  function handleSelectTextKeydown(event) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "105.0.1",
3
+ "version": "105.0.2",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {