@carbon/ibm-products 2.72.0-rc.0 → 2.72.0
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/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.js +19 -0
- package/es/components/ConditionBuilder/utils/useEvent.d.ts +8 -0
- package/es/components/ConditionBuilder/utils/useEvent.js +32 -0
- package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.js +19 -0
- package/lib/components/ConditionBuilder/utils/useEvent.d.ts +8 -0
- package/lib/components/ConditionBuilder/utils/useEvent.js +34 -0
- package/package.json +5 -5
@@ -16,6 +16,7 @@ import { ConditionBuilderContext } from '../ConditionBuilderContext/ConditionBui
|
|
16
16
|
import { handleKeyDownForPopover } from '../utils/handleKeyboardEvents.js';
|
17
17
|
import { checkForMultiSelectOperator, blockClass, getValue } from '../utils/util.js';
|
18
18
|
import { translationsObject } from '../ConditionBuilderContext/translationObject.js';
|
19
|
+
import { useEvent } from '../utils/useEvent.js';
|
19
20
|
|
20
21
|
const ConditionBuilderItem = _ref => {
|
21
22
|
let {
|
@@ -120,6 +121,24 @@ const ConditionBuilderItem = _ref => {
|
|
120
121
|
}
|
121
122
|
}
|
122
123
|
}, [popoverRef, open]);
|
124
|
+
|
125
|
+
//This code is added to address the issue in ComposeModal, where popovers are not getting closed on outside click(#18872)
|
126
|
+
//This is added as a work around to unblock users to use conditionBuilder in Tearsheets or Compose modal
|
127
|
+
useEvent(popoverRef, 'focusout', event => {
|
128
|
+
const focusEvent = event;
|
129
|
+
const relatedTarget = focusEvent.relatedTarget;
|
130
|
+
const popoverEl = popoverRef.current;
|
131
|
+
if (!popoverEl) {
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
const focusLeftPopover = !popoverEl.contains(relatedTarget);
|
135
|
+
const targetInsidePopover = popoverEl.contains(focusEvent.target);
|
136
|
+
const targetEl = focusEvent.target;
|
137
|
+
const focusMovedToDatePicker = targetEl?.closest('.flatpickr-calendar');
|
138
|
+
if ((focusLeftPopover || !targetInsidePopover) && !focusMovedToDatePicker) {
|
139
|
+
closePopover();
|
140
|
+
}
|
141
|
+
});
|
123
142
|
const manageInvalidSelection = () => {
|
124
143
|
//when the user didn't select any value , we need to show as incomplete
|
125
144
|
if (rest['data-name'] === 'propertyField' && !condition?.property || rest['data-name'] === 'operatorField' && !condition?.operator || rest['data-name'] === 'valueField' && !condition?.value) {
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
import { RefObject } from 'react';
|
8
|
+
export declare const useEvent: <E extends keyof GlobalEventHandlersEventMap>(elementOrRef: HTMLElement | RefObject<Element | null>, eventName: E, callback: (event: GlobalEventHandlersEventMap[E]) => void) => void;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2020, 2025
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
import { useRef, useEffect } from 'react';
|
9
|
+
|
10
|
+
const useEvent = (elementOrRef, eventName, callback) => {
|
11
|
+
const savedCallback = useRef(null);
|
12
|
+
useEffect(() => {
|
13
|
+
savedCallback.current = callback;
|
14
|
+
}, [callback]);
|
15
|
+
useEffect(() => {
|
16
|
+
const element = 'current' in elementOrRef ? elementOrRef.current : elementOrRef;
|
17
|
+
if (!element) {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
const handler = event => {
|
21
|
+
if (savedCallback.current) {
|
22
|
+
savedCallback.current(event);
|
23
|
+
}
|
24
|
+
};
|
25
|
+
element.addEventListener(eventName, handler);
|
26
|
+
return () => {
|
27
|
+
element.removeEventListener(eventName, handler);
|
28
|
+
};
|
29
|
+
}, [elementOrRef, eventName]);
|
30
|
+
};
|
31
|
+
|
32
|
+
export { useEvent };
|
@@ -18,6 +18,7 @@ var ConditionBuilderProvider = require('../ConditionBuilderContext/ConditionBuil
|
|
18
18
|
var handleKeyboardEvents = require('../utils/handleKeyboardEvents.js');
|
19
19
|
var util = require('../utils/util.js');
|
20
20
|
var translationObject = require('../ConditionBuilderContext/translationObject.js');
|
21
|
+
var useEvent = require('../utils/useEvent.js');
|
21
22
|
|
22
23
|
const ConditionBuilderItem = _ref => {
|
23
24
|
let {
|
@@ -122,6 +123,24 @@ const ConditionBuilderItem = _ref => {
|
|
122
123
|
}
|
123
124
|
}
|
124
125
|
}, [popoverRef, open]);
|
126
|
+
|
127
|
+
//This code is added to address the issue in ComposeModal, where popovers are not getting closed on outside click(#18872)
|
128
|
+
//This is added as a work around to unblock users to use conditionBuilder in Tearsheets or Compose modal
|
129
|
+
useEvent.useEvent(popoverRef, 'focusout', event => {
|
130
|
+
const focusEvent = event;
|
131
|
+
const relatedTarget = focusEvent.relatedTarget;
|
132
|
+
const popoverEl = popoverRef.current;
|
133
|
+
if (!popoverEl) {
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
const focusLeftPopover = !popoverEl.contains(relatedTarget);
|
137
|
+
const targetInsidePopover = popoverEl.contains(focusEvent.target);
|
138
|
+
const targetEl = focusEvent.target;
|
139
|
+
const focusMovedToDatePicker = targetEl?.closest('.flatpickr-calendar');
|
140
|
+
if ((focusLeftPopover || !targetInsidePopover) && !focusMovedToDatePicker) {
|
141
|
+
closePopover();
|
142
|
+
}
|
143
|
+
});
|
125
144
|
const manageInvalidSelection = () => {
|
126
145
|
//when the user didn't select any value , we need to show as incomplete
|
127
146
|
if (rest['data-name'] === 'propertyField' && !condition?.property || rest['data-name'] === 'operatorField' && !condition?.operator || rest['data-name'] === 'valueField' && !condition?.value) {
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
import { RefObject } from 'react';
|
8
|
+
export declare const useEvent: <E extends keyof GlobalEventHandlersEventMap>(elementOrRef: HTMLElement | RefObject<Element | null>, eventName: E, callback: (event: GlobalEventHandlersEventMap[E]) => void) => void;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2020, 2025
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
'use strict';
|
9
|
+
|
10
|
+
var React = require('react');
|
11
|
+
|
12
|
+
const useEvent = (elementOrRef, eventName, callback) => {
|
13
|
+
const savedCallback = React.useRef(null);
|
14
|
+
React.useEffect(() => {
|
15
|
+
savedCallback.current = callback;
|
16
|
+
}, [callback]);
|
17
|
+
React.useEffect(() => {
|
18
|
+
const element = 'current' in elementOrRef ? elementOrRef.current : elementOrRef;
|
19
|
+
if (!element) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
const handler = event => {
|
23
|
+
if (savedCallback.current) {
|
24
|
+
savedCallback.current(event);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
element.addEventListener(eventName, handler);
|
28
|
+
return () => {
|
29
|
+
element.removeEventListener(eventName, handler);
|
30
|
+
};
|
31
|
+
}, [elementOrRef, eventName]);
|
32
|
+
};
|
33
|
+
|
34
|
+
exports.useEvent = useEvent;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@carbon/ibm-products",
|
3
3
|
"description": "Carbon for IBM Products",
|
4
|
-
"version": "2.72.0
|
4
|
+
"version": "2.72.0",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"main": "lib/index.js",
|
7
7
|
"module": "es/index.js",
|
@@ -81,7 +81,7 @@
|
|
81
81
|
"@storybook/react-vite": "^9.0.13",
|
82
82
|
"@types/react-table": "^7.7.20",
|
83
83
|
"babel-plugin-dev-expression": "^0.2.3",
|
84
|
-
"babel-preset-ibm-cloud-cognitive": "^0.30.0
|
84
|
+
"babel-preset-ibm-cloud-cognitive": "^0.30.0",
|
85
85
|
"chalk": "^4.1.2",
|
86
86
|
"change-case": "5.4.4",
|
87
87
|
"classnames": "^2.5.1",
|
@@ -90,7 +90,7 @@
|
|
90
90
|
"fs-extra": "^11.3.0",
|
91
91
|
"glob": "^11.0.1",
|
92
92
|
"jest": "^29.7.0",
|
93
|
-
"jest-config-ibm-cloud-cognitive": "^1.31.0
|
93
|
+
"jest-config-ibm-cloud-cognitive": "^1.31.0",
|
94
94
|
"jest-environment-jsdom": "^29.7.0",
|
95
95
|
"namor": "^1.1.2",
|
96
96
|
"npm-run-all": "^4.1.5",
|
@@ -109,7 +109,7 @@
|
|
109
109
|
"@babel/runtime": "^7.26.10",
|
110
110
|
"@carbon-labs/react-resizer": "^0.5.0",
|
111
111
|
"@carbon/feature-flags": "^0.28.1",
|
112
|
-
"@carbon/ibm-products-styles": "^2.68.0
|
112
|
+
"@carbon/ibm-products-styles": "^2.68.0",
|
113
113
|
"@carbon/telemetry": "^0.1.0",
|
114
114
|
"@carbon/utilities": "^0.7.0",
|
115
115
|
"@carbon/utilities-react": "0.10.0",
|
@@ -131,5 +131,5 @@
|
|
131
131
|
"react": "^16.8.6 || ^17.0.1 || ^18.2.0 || ^19.0.0",
|
132
132
|
"react-dom": "^16.8.6 || ^17.0.1 || ^18.2.0 || ^19.0.0"
|
133
133
|
},
|
134
|
-
"gitHead": "
|
134
|
+
"gitHead": "996fe987dd30d6c6704e0d48079ec3346f58cd18"
|
135
135
|
}
|