@sustaina/shared-ui 1.65.0 → 1.65.1
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/dist/index.js +56 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7161,6 +7161,10 @@ var ComboboxInner = ({
|
|
|
7161
7161
|
...props
|
|
7162
7162
|
}, ref) => {
|
|
7163
7163
|
const { getLabelField, getValueField } = useFieldNames_default({ fieldNames });
|
|
7164
|
+
const isFocusedRef = React.useRef(false);
|
|
7165
|
+
const isPopoverOpenRef = React.useRef(false);
|
|
7166
|
+
const suppressNextFocusRef = React.useRef(false);
|
|
7167
|
+
const lastFocusEventRef = React.useRef(null);
|
|
7164
7168
|
const { value: openPopover, setValue: setOpenPopover } = useControllableState_default({
|
|
7165
7169
|
defaultValue: false,
|
|
7166
7170
|
value: open
|
|
@@ -7188,18 +7192,27 @@ var ComboboxInner = ({
|
|
|
7188
7192
|
}
|
|
7189
7193
|
return null;
|
|
7190
7194
|
}, [
|
|
7191
|
-
|
|
7192
|
-
getLabelField,
|
|
7193
|
-
placeholder2,
|
|
7195
|
+
isLoading,
|
|
7194
7196
|
selectedValue,
|
|
7197
|
+
placeholder2,
|
|
7198
|
+
currentSelectedOption,
|
|
7195
7199
|
showValueWhenNoMatch,
|
|
7196
|
-
|
|
7197
|
-
|
|
7200
|
+
loadingContent,
|
|
7201
|
+
valueRender,
|
|
7202
|
+
getLabelField
|
|
7198
7203
|
]);
|
|
7204
|
+
const signalBlur = React.useCallback(() => {
|
|
7205
|
+
if (!isFocusedRef.current || !lastFocusEventRef.current) return;
|
|
7206
|
+
isFocusedRef.current = false;
|
|
7207
|
+
suppressNextFocusRef.current = true;
|
|
7208
|
+
onBlur?.(lastFocusEventRef.current);
|
|
7209
|
+
}, [onBlur]);
|
|
7199
7210
|
const handleSelect = React.useCallback(
|
|
7200
7211
|
(selected, option) => {
|
|
7201
7212
|
setSelectedValue(selected);
|
|
7202
7213
|
setOpenPopover(false);
|
|
7214
|
+
isPopoverOpenRef.current = false;
|
|
7215
|
+
signalBlur();
|
|
7203
7216
|
if (typeof onSelect === "function") {
|
|
7204
7217
|
onSelect(selected, option);
|
|
7205
7218
|
}
|
|
@@ -7207,17 +7220,43 @@ var ComboboxInner = ({
|
|
|
7207
7220
|
onOpenChange(false);
|
|
7208
7221
|
}
|
|
7209
7222
|
},
|
|
7210
|
-
[onOpenChange, onSelect, setOpenPopover, setSelectedValue]
|
|
7223
|
+
[onOpenChange, onSelect, setOpenPopover, setSelectedValue, signalBlur]
|
|
7211
7224
|
);
|
|
7212
7225
|
const handleOpenPopover = React.useCallback(
|
|
7213
7226
|
(isOpen) => {
|
|
7214
7227
|
if (disabled || isLoading) return;
|
|
7228
|
+
isPopoverOpenRef.current = isOpen;
|
|
7215
7229
|
setOpenPopover(isOpen);
|
|
7230
|
+
if (!isOpen) {
|
|
7231
|
+
signalBlur();
|
|
7232
|
+
}
|
|
7216
7233
|
if (typeof onOpenChange === "function") {
|
|
7217
7234
|
onOpenChange(isOpen);
|
|
7218
7235
|
}
|
|
7219
7236
|
},
|
|
7220
|
-
[disabled, isLoading, onOpenChange, setOpenPopover]
|
|
7237
|
+
[disabled, isLoading, onOpenChange, setOpenPopover, signalBlur]
|
|
7238
|
+
);
|
|
7239
|
+
const handleFocus = React.useCallback(
|
|
7240
|
+
(event) => {
|
|
7241
|
+
lastFocusEventRef.current = event;
|
|
7242
|
+
if (suppressNextFocusRef.current) {
|
|
7243
|
+
suppressNextFocusRef.current = false;
|
|
7244
|
+
return;
|
|
7245
|
+
}
|
|
7246
|
+
if (isFocusedRef.current) return;
|
|
7247
|
+
isFocusedRef.current = true;
|
|
7248
|
+
onFocus?.(event);
|
|
7249
|
+
},
|
|
7250
|
+
[onFocus]
|
|
7251
|
+
);
|
|
7252
|
+
const handleBlur = React.useCallback(
|
|
7253
|
+
(event) => {
|
|
7254
|
+
if (isPopoverOpenRef.current) return;
|
|
7255
|
+
if (!isFocusedRef.current) return;
|
|
7256
|
+
isFocusedRef.current = false;
|
|
7257
|
+
onBlur?.(event);
|
|
7258
|
+
},
|
|
7259
|
+
[onBlur]
|
|
7221
7260
|
);
|
|
7222
7261
|
const handleClear = React.useCallback(
|
|
7223
7262
|
(event) => {
|
|
@@ -7250,8 +7289,8 @@ var ComboboxInner = ({
|
|
|
7250
7289
|
"data-state": openPopover ? "open" : "closed",
|
|
7251
7290
|
"data-loading": isLoading,
|
|
7252
7291
|
disabled: disabled || isLoading,
|
|
7253
|
-
onFocus,
|
|
7254
|
-
onBlur,
|
|
7292
|
+
onFocus: handleFocus,
|
|
7293
|
+
onBlur: handleBlur,
|
|
7255
7294
|
"data-testid": `combobox-trigger-${name}`,
|
|
7256
7295
|
...props,
|
|
7257
7296
|
children: [
|
|
@@ -7287,6 +7326,11 @@ var ComboboxInner = ({
|
|
|
7287
7326
|
align: "start",
|
|
7288
7327
|
sideOffset: 4,
|
|
7289
7328
|
...popoverContentProps,
|
|
7329
|
+
onCloseAutoFocus: (event) => {
|
|
7330
|
+
event.preventDefault();
|
|
7331
|
+
suppressNextFocusRef.current = false;
|
|
7332
|
+
popoverContentProps?.onCloseAutoFocus?.(event);
|
|
7333
|
+
},
|
|
7290
7334
|
onWheel: (e) => {
|
|
7291
7335
|
e.stopPropagation();
|
|
7292
7336
|
popoverContentProps?.onWheel?.(e);
|
|
@@ -7295,6 +7339,9 @@ var ComboboxInner = ({
|
|
|
7295
7339
|
"p-0 w-(--radix-popper-anchor-width) min-w-(--radix-popper-anchor-width) max-w-(--radix-popper-available-width) rounded-md",
|
|
7296
7340
|
popoverContentProps?.className
|
|
7297
7341
|
),
|
|
7342
|
+
onInteractOutside: (event) => {
|
|
7343
|
+
popoverContentProps?.onInteractOutside?.(event);
|
|
7344
|
+
},
|
|
7298
7345
|
children: virtual ? /* @__PURE__ */ jsx(
|
|
7299
7346
|
VirtualizedCommand_default,
|
|
7300
7347
|
{
|