@ballistix.digital/react-components 9.4.1-rc-355.0 → 9.4.1-rc-357.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/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +75 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +75 -8
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2296,10 +2296,12 @@ const $0c7305af577f9538$var$styles = {
|
|
|
2296
2296
|
var $0c7305af577f9538$export$2e2bcd8739ae039 = $0c7305af577f9538$var$styles;
|
|
2297
2297
|
|
|
2298
2298
|
|
|
2299
|
+
const $cb1b9d36d0757897$var$searchPrefix = '__search__';
|
|
2299
2300
|
const $cb1b9d36d0757897$var$SelectMenu = (props)=>{
|
|
2300
|
-
const { name: name = 'select-menu-form', label: label, description: description, hint: hint, placeholder: placeholder, options: options, required: required, value: value, error: error, isRequired: isRequired = false, isLoading: isLoading, isTouched: isTouched = false, isDisabled: isDisabled, isClearable: isClearable = true, isMultiple: isMultiple = false, isSearchable: isSearchable = true, isSolo: isSolo = false, isOptionalLabelHidden: isOptionalLabelHidden = false, onChange: onChange, onSearchInputChange: onSearchInputChange, onClear: onClear, onBlur: onBlur, dataTestid: dataTestid, styles: stylesOverrides } = props;
|
|
2301
|
+
const { name: name = 'select-menu-form', label: label, description: description, hint: hint, placeholder: placeholder, options: options, required: required, value: value, error: error, isRequired: isRequired = false, isLoading: isLoading, isTouched: isTouched = false, isDisabled: isDisabled, isClearable: isClearable = true, isMultiple: isMultiple = false, isSearchable: isSearchable = true, isSolo: isSolo = false, isOptionalLabelHidden: isOptionalLabelHidden = false, onChange: onChange, onSearchInputChange: onSearchInputChange, onClear: onClear, onBlur: onBlur, isSearchOptionEnabled: isSearchOptionEnabled = false, searchInputOptionRenderer: searchInputOptionRenderer, dataTestid: dataTestid, styles: stylesOverrides } = props;
|
|
2301
2302
|
const [isFocus, setIsFocus] = (0, $iA2ta$react.useState)(true);
|
|
2302
2303
|
const [state, setState] = (0, $iA2ta$react.useState)(value ?? null);
|
|
2304
|
+
const [searchValue, setSearchValue] = (0, $iA2ta$react.useState)();
|
|
2303
2305
|
const isValid = error === undefined;
|
|
2304
2306
|
const selectDataTestid = dataTestid ?? `form-select-${name}`;
|
|
2305
2307
|
const handleGenerateStyle = ()=>{
|
|
@@ -2314,7 +2316,27 @@ const $cb1b9d36d0757897$var$SelectMenu = (props)=>{
|
|
|
2314
2316
|
setState(selectValue);
|
|
2315
2317
|
onChange && onChange(selectValue);
|
|
2316
2318
|
setIsFocus(false);
|
|
2319
|
+
if (isSearchOptionEnabled) setSearchValue(null);
|
|
2317
2320
|
};
|
|
2321
|
+
const handleSearchInputChange = (e)=>{
|
|
2322
|
+
if (isSearchOptionEnabled) setSearchValue(e.target.value);
|
|
2323
|
+
onSearchInputChange?.(e);
|
|
2324
|
+
};
|
|
2325
|
+
const computedOptions = (0, $iA2ta$react.useMemo)(()=>{
|
|
2326
|
+
if (!isSearchOptionEnabled || !searchValue) return options;
|
|
2327
|
+
if (options.some((opt)=>opt.label.toLowerCase().includes(searchValue.toLowerCase()))) return options;
|
|
2328
|
+
return [
|
|
2329
|
+
...options,
|
|
2330
|
+
{
|
|
2331
|
+
label: searchValue,
|
|
2332
|
+
value: $cb1b9d36d0757897$var$searchPrefix + searchValue
|
|
2333
|
+
}
|
|
2334
|
+
];
|
|
2335
|
+
}, [
|
|
2336
|
+
isSearchOptionEnabled,
|
|
2337
|
+
options,
|
|
2338
|
+
searchValue
|
|
2339
|
+
]);
|
|
2318
2340
|
const styles = handleGenerateStyle();
|
|
2319
2341
|
// Simulate onClear event.
|
|
2320
2342
|
(0, $iA2ta$react.useEffect)(()=>{
|
|
@@ -2332,10 +2354,37 @@ const $cb1b9d36d0757897$var$SelectMenu = (props)=>{
|
|
|
2332
2354
|
]);
|
|
2333
2355
|
// listen to value changes.
|
|
2334
2356
|
(0, $iA2ta$react.useEffect)(()=>{
|
|
2357
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
2335
2358
|
setState(value ?? null);
|
|
2336
2359
|
}, [
|
|
2337
2360
|
value
|
|
2338
2361
|
]);
|
|
2362
|
+
(0, $iA2ta$react.useEffect)(()=>{
|
|
2363
|
+
const targetNode = document.querySelector(`.bx-select-menu-${name}`);
|
|
2364
|
+
if (!targetNode) return;
|
|
2365
|
+
targetNode.setAttribute('aria-labelledby', `${name}-label`);
|
|
2366
|
+
}, [
|
|
2367
|
+
name
|
|
2368
|
+
]);
|
|
2369
|
+
// Reset search value when the dropdown closes (aria-expanded → false).
|
|
2370
|
+
(0, $iA2ta$react.useEffect)(()=>{
|
|
2371
|
+
if (!isSearchOptionEnabled) return;
|
|
2372
|
+
const targetNode = document.querySelector(`.bx-select-menu-${name}`);
|
|
2373
|
+
if (!targetNode) return;
|
|
2374
|
+
const observer = new MutationObserver((mutations)=>{
|
|
2375
|
+
for (const mutation of mutations)if (mutation.attributeName === 'aria-expanded' && targetNode.getAttribute('aria-expanded') === 'false') setSearchValue(null);
|
|
2376
|
+
});
|
|
2377
|
+
observer.observe(targetNode, {
|
|
2378
|
+
attributes: true,
|
|
2379
|
+
attributeFilter: [
|
|
2380
|
+
'aria-expanded'
|
|
2381
|
+
]
|
|
2382
|
+
});
|
|
2383
|
+
return ()=>observer.disconnect();
|
|
2384
|
+
}, [
|
|
2385
|
+
isSearchOptionEnabled,
|
|
2386
|
+
name
|
|
2387
|
+
]);
|
|
2339
2388
|
const formattedError = (0, $iA2ta$react.useMemo)(()=>{
|
|
2340
2389
|
if (error) return JSON.stringify(error).replaceAll('"', '');
|
|
2341
2390
|
return null;
|
|
@@ -2345,6 +2394,12 @@ const $cb1b9d36d0757897$var$SelectMenu = (props)=>{
|
|
|
2345
2394
|
return (0, $iA2ta$reactjsxruntime.jsxs)("div", {
|
|
2346
2395
|
className: styles.container,
|
|
2347
2396
|
"data-testid": selectDataTestid,
|
|
2397
|
+
onBlur: (e)=>{
|
|
2398
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
2399
|
+
setIsFocus(false);
|
|
2400
|
+
if (isSearchOptionEnabled) setSearchValue('');
|
|
2401
|
+
}
|
|
2402
|
+
},
|
|
2348
2403
|
children: [
|
|
2349
2404
|
(0, $iA2ta$reactjsxruntime.jsx)((0, $9314e0aa7f1e874e$export$2e2bcd8739ae039), {
|
|
2350
2405
|
name: name,
|
|
@@ -2359,16 +2414,13 @@ const $cb1b9d36d0757897$var$SelectMenu = (props)=>{
|
|
|
2359
2414
|
className: (0, $622cd2936b18c771$export$4370d69198e9314a)(styles.container, styles.wrapperContainer),
|
|
2360
2415
|
children: [
|
|
2361
2416
|
(0, $iA2ta$reactjsxruntime.jsx)("div", {
|
|
2417
|
+
id: `select-menu-control-${name}`,
|
|
2362
2418
|
"data-cy": `form-select-${name}`,
|
|
2363
2419
|
"data-testid": `${selectDataTestid}-control`,
|
|
2364
2420
|
children: (0, $iA2ta$reactjsxruntime.jsx)((0, ($parcel$interopDefault($iA2ta$reacttailwindcssselect))), {
|
|
2365
2421
|
primaryColor: "primary",
|
|
2366
2422
|
//
|
|
2367
2423
|
placeholder: placeholder?.select,
|
|
2368
|
-
noOptionsMessage: (0, $iA2ta$reactjsxruntime.jsx)("p", {
|
|
2369
|
-
className: styles.emptyState,
|
|
2370
|
-
children: placeholder?.emptyState ?? 'No results found'
|
|
2371
|
-
}),
|
|
2372
2424
|
searchInputPlaceholder: placeholder?.searchInput,
|
|
2373
2425
|
//
|
|
2374
2426
|
loading: isLoading,
|
|
@@ -2377,14 +2429,29 @@ const $cb1b9d36d0757897$var$SelectMenu = (props)=>{
|
|
|
2377
2429
|
isMultiple: isMultiple,
|
|
2378
2430
|
isSearchable: isSearchable,
|
|
2379
2431
|
//
|
|
2380
|
-
options:
|
|
2432
|
+
options: computedOptions,
|
|
2381
2433
|
//
|
|
2382
2434
|
value: state,
|
|
2383
2435
|
onChange: handleChange,
|
|
2384
|
-
onSearchInputChange:
|
|
2436
|
+
onSearchInputChange: handleSearchInputChange,
|
|
2385
2437
|
//
|
|
2438
|
+
formatOptionLabel: (data)=>{
|
|
2439
|
+
if (isSearchOptionEnabled && searchInputOptionRenderer && data.value.startsWith($cb1b9d36d0757897$var$searchPrefix)) {
|
|
2440
|
+
const tagItem = (0, $iA2ta$reactjsxruntime.jsx)("div", {
|
|
2441
|
+
className: styles.tagItem,
|
|
2442
|
+
children: (0, $iA2ta$reactjsxruntime.jsx)("p", {
|
|
2443
|
+
className: styles.tagItemText,
|
|
2444
|
+
children: data.label
|
|
2445
|
+
})
|
|
2446
|
+
});
|
|
2447
|
+
return (0, $iA2ta$reactjsxruntime.jsx)((0, $iA2ta$reactjsxruntime.Fragment), {
|
|
2448
|
+
children: searchInputOptionRenderer(tagItem)
|
|
2449
|
+
});
|
|
2450
|
+
}
|
|
2451
|
+
return data.label;
|
|
2452
|
+
},
|
|
2386
2453
|
classNames: {
|
|
2387
|
-
menuButton: ()=>(0, $622cd2936b18c771$export$4370d69198e9314a)(styles.input, state === null && '*:text-gray-300! ', state === null && !isValid && isTouched && '*:text-red-300!'),
|
|
2454
|
+
menuButton: ()=>(0, $622cd2936b18c771$export$4370d69198e9314a)(styles.input, `bx-select-menu-${name}`, state === null && '*:text-gray-300! ', state === null && !isValid && isTouched && '*:text-red-300!'),
|
|
2388
2455
|
menu: styles.menu,
|
|
2389
2456
|
tagItem: ()=>styles.tagItem,
|
|
2390
2457
|
tagItemText: styles.tagItemText,
|