@ssa-ui-kit/core 2.15.0-canary-3fd3271-20250501 → 2.15.0-canary-9a56baa-20250506
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/components/Typeahead/Typeahead.context.d.ts +12 -12
- package/dist/components/Typeahead/Typeahead.d.ts +1 -1
- package/dist/components/Typeahead/types.d.ts +4 -5
- package/dist/components/Typeahead/useTypeahead.d.ts +15 -16
- package/dist/index.js +262 -237
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -11611,10 +11611,14 @@ function Trigger_EMOTION_STRINGIFIED_CSS_ERROR_() { return "You have tried to st
|
|
|
11611
11611
|
|
|
11612
11612
|
|
|
11613
11613
|
var Trigger_ref = true ? {
|
|
11614
|
+
name: "5bhc30",
|
|
11615
|
+
styles: "margin-bottom:8px"
|
|
11616
|
+
} : 0;
|
|
11617
|
+
var Trigger_ref2 = true ? {
|
|
11614
11618
|
name: "jpxugn",
|
|
11615
11619
|
styles: "margin:0 14px"
|
|
11616
11620
|
} : 0;
|
|
11617
|
-
var
|
|
11621
|
+
var Trigger_ref3 = true ? {
|
|
11618
11622
|
name: "ud49p1",
|
|
11619
11623
|
styles: "color:inherit;&::first-letter{text-transform:uppercase;}"
|
|
11620
11624
|
} : 0;
|
|
@@ -11654,8 +11658,9 @@ const Trigger = () => {
|
|
|
11654
11658
|
disabled: disabled,
|
|
11655
11659
|
"data-testid": "daterangepicker",
|
|
11656
11660
|
className: triggerClassname,
|
|
11657
|
-
children: [(0,jsx_runtime_namespaceObject.jsx)(FieldLabel, {
|
|
11661
|
+
children: [label && (0,jsx_runtime_namespaceObject.jsx)(FieldLabel, {
|
|
11658
11662
|
htmlFor: lastFocusedElement === 'from' ? nameFrom : nameTo,
|
|
11663
|
+
css: Trigger_ref,
|
|
11659
11664
|
children: label
|
|
11660
11665
|
}), (0,jsx_runtime_namespaceObject.jsx)(FieldControl, {
|
|
11661
11666
|
children: (0,jsx_runtime_namespaceObject.jsxs)(Wrapper_Wrapper, {
|
|
@@ -11672,7 +11677,7 @@ const Trigger = () => {
|
|
|
11672
11677
|
name: "carrot-right",
|
|
11673
11678
|
size: 18,
|
|
11674
11679
|
color: theme.colors.greyDarker80,
|
|
11675
|
-
css:
|
|
11680
|
+
css: Trigger_ref2
|
|
11676
11681
|
}), (0,jsx_runtime_namespaceObject.jsx)(TriggerInput, {
|
|
11677
11682
|
datepickerType: "to",
|
|
11678
11683
|
onClick: () => {
|
|
@@ -11705,7 +11710,7 @@ const Trigger = () => {
|
|
|
11705
11710
|
children: helperText
|
|
11706
11711
|
}), (0,jsx_runtime_namespaceObject.jsx)(FieldError, {
|
|
11707
11712
|
children: errorMessage ? errorMessage.map((error, index) => (0,jsx_runtime_namespaceObject.jsx)("span", {
|
|
11708
|
-
css:
|
|
11713
|
+
css: Trigger_ref3,
|
|
11709
11714
|
children: error
|
|
11710
11715
|
}, `error-${index}`)) : helperText
|
|
11711
11716
|
}), (0,jsx_runtime_namespaceObject.jsx)(FieldSuccess, {
|
|
@@ -11812,7 +11817,7 @@ const useDateRangePicker = ({
|
|
|
11812
11817
|
setValue,
|
|
11813
11818
|
resetField,
|
|
11814
11819
|
setFocus
|
|
11815
|
-
} = (0,external_react_hook_form_namespaceObject.useFormContext)();
|
|
11820
|
+
} = (0,external_react_hook_form_namespaceObject.useFormContext)() || (0,external_react_hook_form_namespaceObject.useForm)();
|
|
11816
11821
|
const nameFrom = `${_name}From`;
|
|
11817
11822
|
const nameTo = `${_name}To`;
|
|
11818
11823
|
const inputValueFrom = (0,external_react_hook_form_namespaceObject.useWatch)({
|
|
@@ -17514,7 +17519,6 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17514
17519
|
options: [],
|
|
17515
17520
|
placeholder: '',
|
|
17516
17521
|
useFormResult: {},
|
|
17517
|
-
error: undefined,
|
|
17518
17522
|
setValue: () => {
|
|
17519
17523
|
/* no-op */
|
|
17520
17524
|
},
|
|
@@ -17522,7 +17526,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17522
17526
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
17523
17527
|
return {};
|
|
17524
17528
|
},
|
|
17525
|
-
|
|
17529
|
+
handleChange: () => {
|
|
17526
17530
|
/* no-op */
|
|
17527
17531
|
},
|
|
17528
17532
|
handleClearAll: () => {
|
|
@@ -17542,6 +17546,9 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17542
17546
|
},
|
|
17543
17547
|
handleRemoveSelectedClick: () => () => {
|
|
17544
17548
|
/* no-op */
|
|
17549
|
+
},
|
|
17550
|
+
handleSelectedClick: () => {
|
|
17551
|
+
/* no-op */
|
|
17545
17552
|
}
|
|
17546
17553
|
});
|
|
17547
17554
|
const useTypeaheadContext = () => external_react_namespaceObject.useContext(TypeaheadContext);
|
|
@@ -17549,18 +17556,10 @@ const useTypeaheadContext = () => external_react_namespaceObject.useContext(Type
|
|
|
17549
17556
|
|
|
17550
17557
|
|
|
17551
17558
|
|
|
17552
|
-
const findExactMatch = (input, options) => {
|
|
17553
|
-
const normalizedInput = input.toLowerCase();
|
|
17554
|
-
return Object.values(options).find(opt => {
|
|
17555
|
-
const labelText = (opt.label ?? opt.value).toString().toLowerCase();
|
|
17556
|
-
return labelText === normalizedInput;
|
|
17557
|
-
});
|
|
17558
|
-
};
|
|
17559
17559
|
const useTypeahead = ({
|
|
17560
17560
|
name = 'typeahead-input',
|
|
17561
17561
|
isOpen: isInitOpen,
|
|
17562
17562
|
selectedItems,
|
|
17563
|
-
defaultSelectedItems,
|
|
17564
17563
|
isDisabled,
|
|
17565
17564
|
isMultiple,
|
|
17566
17565
|
children,
|
|
@@ -17573,8 +17572,8 @@ const useTypeahead = ({
|
|
|
17573
17572
|
error,
|
|
17574
17573
|
success,
|
|
17575
17574
|
placeholder,
|
|
17576
|
-
|
|
17577
|
-
|
|
17575
|
+
register,
|
|
17576
|
+
setValue,
|
|
17578
17577
|
onChange,
|
|
17579
17578
|
onClearAll,
|
|
17580
17579
|
onRemoveSelectedClick,
|
|
@@ -17582,240 +17581,266 @@ const useTypeahead = ({
|
|
|
17582
17581
|
renderOption
|
|
17583
17582
|
}) => {
|
|
17584
17583
|
const inputName = `${name}-text`;
|
|
17585
|
-
const [isOpen,
|
|
17586
|
-
|
|
17587
|
-
|
|
17588
|
-
|
|
17589
|
-
const [
|
|
17590
|
-
|
|
17591
|
-
|
|
17592
|
-
|
|
17593
|
-
|
|
17594
|
-
const
|
|
17595
|
-
const
|
|
17596
|
-
ref: inputRef
|
|
17597
|
-
} = (0,hooks_namespaceObject.useElementSize)();
|
|
17584
|
+
const [isOpen, setIsOpen] = (0,external_react_namespaceObject.useState)(isInitOpen || false);
|
|
17585
|
+
const [selected, setSelected] = (0,external_react_namespaceObject.useState)(selectedItems || []);
|
|
17586
|
+
const [optionsWithKey, setOptionsWithKey] = (0,external_react_namespaceObject.useState)({});
|
|
17587
|
+
const [isEmpty, setIsEmpty] = (0,external_react_namespaceObject.useState)(true);
|
|
17588
|
+
const [isFirstRender, setFirstRender] = (0,external_react_namespaceObject.useState)(true);
|
|
17589
|
+
const [items, setItems] = (0,external_react_namespaceObject.useState)();
|
|
17590
|
+
const [inputValue, setInputValue] = (0,external_react_namespaceObject.useState)('');
|
|
17591
|
+
const [status, setStatus] = (0,external_react_namespaceObject.useState)('basic');
|
|
17592
|
+
const [firstSuggestion, setFirstSuggestion] = (0,external_react_namespaceObject.useState)('');
|
|
17593
|
+
const inputRef = (0,external_react_namespaceObject.useRef)(null);
|
|
17594
|
+
const typeaheadId = (0,external_react_namespaceObject.useId)();
|
|
17598
17595
|
const triggerRef = (0,external_react_namespaceObject.useRef)(null);
|
|
17599
|
-
const
|
|
17600
|
-
const form = (0,external_react_hook_form_namespaceObject.useFormContext)() ?? defaultForm;
|
|
17601
|
-
const {
|
|
17602
|
-
register,
|
|
17603
|
-
setValue
|
|
17604
|
-
} = form;
|
|
17596
|
+
const useFormResult = (0,external_react_hook_form_namespaceObject.useForm)();
|
|
17605
17597
|
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17606
|
-
if (!
|
|
17607
|
-
|
|
17598
|
+
if (!register) {
|
|
17599
|
+
console.warn('Typeahead component must be used within a Form component');
|
|
17608
17600
|
}
|
|
17601
|
+
}, []);
|
|
17602
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17609
17603
|
if (isMultiple) {
|
|
17610
17604
|
setValue?.(name, selected, {
|
|
17611
|
-
shouldDirty:
|
|
17605
|
+
shouldDirty: !isFirstRender
|
|
17612
17606
|
});
|
|
17607
|
+
setInputValue('');
|
|
17608
|
+
setFirstSuggestion('');
|
|
17613
17609
|
} else {
|
|
17614
|
-
setValue?.(name, selected[0], {
|
|
17615
|
-
shouldDirty:
|
|
17610
|
+
setValue?.(name, selected.length ? selected[0] : [], {
|
|
17611
|
+
shouldDirty: !isFirstRender
|
|
17616
17612
|
});
|
|
17617
17613
|
}
|
|
17618
|
-
|
|
17619
|
-
|
|
17620
|
-
|
|
17621
|
-
|
|
17622
|
-
|
|
17623
|
-
|
|
17624
|
-
|
|
17625
|
-
|
|
17614
|
+
handleOnEmptyChange(!selected.length);
|
|
17615
|
+
}, [selected]);
|
|
17616
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17617
|
+
if (isDisabled && isOpen) {
|
|
17618
|
+
setIsOpen(false);
|
|
17619
|
+
}
|
|
17620
|
+
}, [isDisabled]);
|
|
17621
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17622
|
+
const status = success ? 'success' : useFormResult.formState.errors[name] ? 'error' : 'basic';
|
|
17623
|
+
setStatus(status);
|
|
17624
|
+
}, [useFormResult.formState.errors[name], success]);
|
|
17625
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17626
|
+
if (error) {
|
|
17627
|
+
useFormResult.setError(name, error);
|
|
17628
|
+
} else {
|
|
17629
|
+
setStatus('basic');
|
|
17630
|
+
useFormResult.resetField(name);
|
|
17631
|
+
}
|
|
17632
|
+
}, [error]);
|
|
17633
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17634
|
+
processChildren({
|
|
17635
|
+
selectedLocal: selected
|
|
17626
17636
|
});
|
|
17627
|
-
return opts;
|
|
17628
17637
|
}, [children]);
|
|
17629
|
-
|
|
17630
|
-
|
|
17631
|
-
if (
|
|
17632
|
-
|
|
17633
|
-
|
|
17634
|
-
|
|
17635
|
-
|
|
17636
|
-
|
|
17637
|
-
|
|
17638
|
-
|
|
17639
|
-
|
|
17640
|
-
|
|
17641
|
-
|
|
17642
|
-
|
|
17643
|
-
} = child.props;
|
|
17644
|
-
const text = (label ?? value)?.toString().toLowerCase() || '';
|
|
17645
|
-
return text.includes(needle);
|
|
17638
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17639
|
+
setSelected(selectedItems || []);
|
|
17640
|
+
if (selectedItems?.length) {
|
|
17641
|
+
if (!isMultiple) {
|
|
17642
|
+
const currentOption = optionsWithKey[selectedItems[0]];
|
|
17643
|
+
const optionText = currentOption && (currentOption.children || currentOption.label || currentOption.value);
|
|
17644
|
+
setInputValue(`${optionText}`);
|
|
17645
|
+
}
|
|
17646
|
+
} else {
|
|
17647
|
+
setInputValue('');
|
|
17648
|
+
setFirstSuggestion('');
|
|
17649
|
+
}
|
|
17650
|
+
processChildren({
|
|
17651
|
+
selectedLocal: selectedItems || []
|
|
17646
17652
|
});
|
|
17647
|
-
}, [
|
|
17648
|
-
|
|
17649
|
-
|
|
17650
|
-
|
|
17651
|
-
|
|
17653
|
+
}, [selectedItems]);
|
|
17654
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17655
|
+
const childrenArray = external_react_default().Children.toArray(children).filter(Boolean);
|
|
17656
|
+
const filteredOptions = [...childrenArray];
|
|
17657
|
+
const childItems = filteredOptions.map((child, index) => {
|
|
17652
17658
|
const {
|
|
17659
|
+
id,
|
|
17653
17660
|
value,
|
|
17654
17661
|
label,
|
|
17655
|
-
id,
|
|
17656
17662
|
isDisabled
|
|
17657
17663
|
} = child.props;
|
|
17664
|
+
const isActive = selected.includes(child.props.value);
|
|
17658
17665
|
return /*#__PURE__*/external_react_default().cloneElement(child, {
|
|
17659
|
-
...child.props,
|
|
17660
17666
|
index,
|
|
17667
|
+
...child.props,
|
|
17661
17668
|
isActive,
|
|
17662
17669
|
isDisabled,
|
|
17663
|
-
|
|
17670
|
+
id,
|
|
17664
17671
|
'aria-selected': isActive,
|
|
17665
17672
|
'aria-labelledby': `typeahead-label-${name}`,
|
|
17666
|
-
|
|
17667
|
-
|
|
17673
|
+
role: 'option',
|
|
17674
|
+
onClick: event => {
|
|
17675
|
+
event.preventDefault();
|
|
17668
17676
|
if (!isDisabled) {
|
|
17669
|
-
|
|
17670
|
-
handleChange({
|
|
17671
|
-
value,
|
|
17672
|
-
shouldClose
|
|
17673
|
-
});
|
|
17677
|
+
handleChange(child.props.value);
|
|
17674
17678
|
}
|
|
17675
17679
|
},
|
|
17676
|
-
children: renderOption
|
|
17680
|
+
children: renderOption ? renderOption({
|
|
17677
17681
|
value: id || value,
|
|
17678
|
-
input: inputValue,
|
|
17682
|
+
input: inputValue || '',
|
|
17679
17683
|
label
|
|
17680
|
-
})
|
|
17684
|
+
}) : child.props.children || child.props.label || child.props.value
|
|
17681
17685
|
});
|
|
17682
17686
|
});
|
|
17683
|
-
|
|
17684
|
-
|
|
17685
|
-
|
|
17686
|
-
|
|
17687
|
-
|
|
17688
|
-
if (!
|
|
17689
|
-
|
|
17690
|
-
|
|
17691
|
-
|
|
17687
|
+
setItems(childItems);
|
|
17688
|
+
}, [inputValue, optionsWithKey, selected]);
|
|
17689
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17690
|
+
if (!isMultiple && Object.keys(optionsWithKey).length) {
|
|
17691
|
+
const foundItem = Object.values(optionsWithKey).find(item => item.label === inputValue);
|
|
17692
|
+
if (!foundItem && selected.length) {
|
|
17693
|
+
setSelected([]);
|
|
17694
|
+
}
|
|
17695
|
+
if (foundItem && !selected.includes(foundItem?.value)) {
|
|
17696
|
+
setSelected([foundItem.value]);
|
|
17697
|
+
}
|
|
17698
|
+
}
|
|
17699
|
+
}, [optionsWithKey, inputValue]);
|
|
17700
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17701
|
+
processSingleSelected({
|
|
17702
|
+
optionsWithKeyLocal: optionsWithKey,
|
|
17703
|
+
selectedLocal: selected
|
|
17704
|
+
});
|
|
17705
|
+
}, [selected]);
|
|
17706
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17707
|
+
if (inputValue) {
|
|
17708
|
+
const newFirstSuggestion = Object.values(optionsWithKey)?.find(item => {
|
|
17709
|
+
const label = (0,utils_namespaceObject.propOr)('', 'label')(item);
|
|
17710
|
+
return label.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
17711
|
+
});
|
|
17712
|
+
const firstSuggestionLabel = (0,utils_namespaceObject.propOr)('', 'label')(newFirstSuggestion);
|
|
17713
|
+
const humanSuggestionLabel = inputValue.concat(firstSuggestionLabel.slice(inputValue.length));
|
|
17714
|
+
setFirstSuggestion(humanSuggestionLabel);
|
|
17715
|
+
} else {
|
|
17716
|
+
setFirstSuggestion('');
|
|
17717
|
+
if (isMultiple) {
|
|
17718
|
+
setInputValue('');
|
|
17692
17719
|
}
|
|
17693
17720
|
}
|
|
17694
|
-
|
|
17695
|
-
|
|
17696
|
-
|
|
17697
|
-
|
|
17698
|
-
|
|
17721
|
+
}, [inputValue, items, selected]);
|
|
17722
|
+
const processSingleSelected = ({
|
|
17723
|
+
optionsWithKeyLocal = {},
|
|
17724
|
+
selectedLocal = []
|
|
17725
|
+
}) => {
|
|
17726
|
+
if (!isMultiple && selectedLocal.length && Object.keys(optionsWithKeyLocal).length) {
|
|
17727
|
+
const currentOption = optionsWithKeyLocal[selectedLocal[0]];
|
|
17728
|
+
const optionText = currentOption && (currentOption.children || currentOption.label || currentOption.value);
|
|
17729
|
+
setInputValue(`${optionText}`);
|
|
17699
17730
|
}
|
|
17700
|
-
_setIsOpen(open);
|
|
17701
17731
|
};
|
|
17702
|
-
const
|
|
17703
|
-
|
|
17704
|
-
shouldClose = true,
|
|
17705
|
-
resetInput = true
|
|
17732
|
+
const processChildren = ({
|
|
17733
|
+
selectedLocal
|
|
17706
17734
|
}) => {
|
|
17707
|
-
|
|
17708
|
-
const
|
|
17709
|
-
|
|
17710
|
-
|
|
17711
|
-
|
|
17712
|
-
|
|
17713
|
-
|
|
17714
|
-
|
|
17715
|
-
|
|
17716
|
-
|
|
17735
|
+
const keyedOptions = {};
|
|
17736
|
+
const childItems = external_react_default().Children.toArray(children).filter(Boolean).map((child, index) => {
|
|
17737
|
+
keyedOptions[child.props.value] = {
|
|
17738
|
+
...child.props
|
|
17739
|
+
};
|
|
17740
|
+
return /*#__PURE__*/external_react_default().cloneElement(child, {
|
|
17741
|
+
index,
|
|
17742
|
+
...child.props
|
|
17743
|
+
});
|
|
17744
|
+
});
|
|
17745
|
+
setOptionsWithKey(keyedOptions);
|
|
17746
|
+
setItems(childItems);
|
|
17747
|
+
processSingleSelected({
|
|
17748
|
+
optionsWithKeyLocal: keyedOptions,
|
|
17749
|
+
selectedLocal
|
|
17750
|
+
});
|
|
17751
|
+
setFirstRender(false);
|
|
17752
|
+
};
|
|
17753
|
+
const handleOnEmptyChange = newIsEmptyValue => {
|
|
17754
|
+
if (newIsEmptyValue !== isEmpty) {
|
|
17755
|
+
setIsEmpty(newIsEmptyValue);
|
|
17756
|
+
onEmptyChange?.(newIsEmptyValue);
|
|
17717
17757
|
}
|
|
17718
|
-
|
|
17719
|
-
|
|
17758
|
+
};
|
|
17759
|
+
const handleOpenChange = open => {
|
|
17760
|
+
if (!isDisabled) {
|
|
17761
|
+
setIsOpen(open);
|
|
17720
17762
|
}
|
|
17721
|
-
onChange?.(value, !alreadySelected);
|
|
17722
|
-
onEmptyChange?.(updatedSelected.length === 0);
|
|
17723
17763
|
};
|
|
17724
|
-
const
|
|
17725
|
-
if (isDisabled)
|
|
17726
|
-
|
|
17727
|
-
|
|
17728
|
-
|
|
17729
|
-
|
|
17764
|
+
const handleChange = changingValue => {
|
|
17765
|
+
if (isDisabled || changingValue === undefined) {
|
|
17766
|
+
return;
|
|
17767
|
+
}
|
|
17768
|
+
const isNewSelected = true;
|
|
17769
|
+
const isChangingItemSelected = selected.includes(changingValue);
|
|
17770
|
+
if (isMultiple) {
|
|
17771
|
+
setSelected(currentSelected => isChangingItemSelected ? currentSelected.filter(current => current !== changingValue) : [...currentSelected, changingValue]);
|
|
17772
|
+
setInputValue('');
|
|
17773
|
+
} else {
|
|
17774
|
+
if (selected[0] === changingValue) {
|
|
17775
|
+
setSelected([]);
|
|
17776
|
+
setInputValue('');
|
|
17777
|
+
} else {
|
|
17778
|
+
setSelected([changingValue]);
|
|
17779
|
+
}
|
|
17780
|
+
}
|
|
17730
17781
|
setIsOpen(false);
|
|
17731
|
-
|
|
17732
|
-
form.trigger(name);
|
|
17782
|
+
setFirstSuggestion('');
|
|
17733
17783
|
inputRef.current?.focus();
|
|
17734
|
-
|
|
17735
|
-
|
|
17784
|
+
setStatus('basic');
|
|
17785
|
+
useFormResult.clearErrors(name);
|
|
17786
|
+
useFormResult.trigger(name);
|
|
17787
|
+
onChange?.(changingValue, isNewSelected);
|
|
17736
17788
|
};
|
|
17737
|
-
const
|
|
17738
|
-
|
|
17739
|
-
setRawInput(input);
|
|
17740
|
-
if (!autoSelect || !filterOptions) return;
|
|
17741
|
-
const match = findExactMatch(input, optionsWithKey);
|
|
17742
|
-
if (match) {
|
|
17743
|
-
handleChange({
|
|
17744
|
-
value: match.value,
|
|
17745
|
-
shouldClose: false
|
|
17746
|
-
});
|
|
17789
|
+
const handleClearAll = event => {
|
|
17790
|
+
if (isDisabled) {
|
|
17747
17791
|
return;
|
|
17748
17792
|
}
|
|
17749
|
-
|
|
17750
|
-
|
|
17751
|
-
|
|
17752
|
-
|
|
17753
|
-
|
|
17754
|
-
|
|
17755
|
-
|
|
17756
|
-
|
|
17793
|
+
event.stopPropagation();
|
|
17794
|
+
event.preventDefault();
|
|
17795
|
+
setSelected([]);
|
|
17796
|
+
setInputValue('');
|
|
17797
|
+
setIsOpen(false);
|
|
17798
|
+
setFirstSuggestion('');
|
|
17799
|
+
useFormResult.trigger(name);
|
|
17800
|
+
inputRef.current?.focus();
|
|
17801
|
+
onClearAll?.();
|
|
17757
17802
|
};
|
|
17758
|
-
const handleInputClick =
|
|
17759
|
-
e.stopPropagation();
|
|
17760
|
-
e.preventDefault();
|
|
17803
|
+
const handleInputClick = event => {
|
|
17761
17804
|
if (!isDisabled) {
|
|
17762
17805
|
inputRef.current?.focus();
|
|
17763
17806
|
setIsOpen(true);
|
|
17764
17807
|
}
|
|
17808
|
+
event.stopPropagation();
|
|
17809
|
+
event.preventDefault();
|
|
17765
17810
|
};
|
|
17766
|
-
const handleInputKeyDown =
|
|
17767
|
-
|
|
17768
|
-
|
|
17769
|
-
|
|
17770
|
-
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
|
|
17774
|
-
|
|
17811
|
+
const handleInputKeyDown = event => {
|
|
17812
|
+
if (['Space'].includes(event.code) && !firstSuggestion) {
|
|
17813
|
+
setIsOpen(true);
|
|
17814
|
+
inputRef.current?.focus();
|
|
17815
|
+
event.stopPropagation();
|
|
17816
|
+
event.preventDefault();
|
|
17817
|
+
} else if (['Tab', 'Enter'].includes(event.code) && firstSuggestion && firstSuggestion !== inputValue) {
|
|
17818
|
+
const foundItem = Object.values(optionsWithKey).find(item => `${item.label}`.toLowerCase() === firstSuggestion.toLowerCase());
|
|
17819
|
+
handleChange(foundItem?.value);
|
|
17820
|
+
if (foundItem) {
|
|
17821
|
+
setInputValue(`${foundItem?.label}`);
|
|
17775
17822
|
}
|
|
17776
|
-
|
|
17777
|
-
return;
|
|
17778
|
-
}
|
|
17779
|
-
|
|
17780
|
-
|
|
17781
|
-
|
|
17782
|
-
|
|
17783
|
-
shouldClose: false
|
|
17784
|
-
});
|
|
17785
|
-
e.preventDefault();
|
|
17786
|
-
return;
|
|
17787
|
-
}
|
|
17788
|
-
if (!isOpen && firstSuggestion !== inputValue) {
|
|
17823
|
+
event.preventDefault();
|
|
17824
|
+
return false;
|
|
17825
|
+
} else if (isMultiple && event.code === 'Backspace' && selected.length > 0 && !firstSuggestion) {
|
|
17826
|
+
handleChange(selected[selected.length - 1]);
|
|
17827
|
+
event.preventDefault();
|
|
17828
|
+
return false;
|
|
17829
|
+
} else if (!isOpen && firstSuggestion !== inputValue) {
|
|
17789
17830
|
setIsOpen(true);
|
|
17790
17831
|
}
|
|
17791
17832
|
};
|
|
17792
|
-
const
|
|
17793
|
-
|
|
17794
|
-
handleChange({
|
|
17795
|
-
value
|
|
17796
|
-
});
|
|
17797
|
-
onRemoveSelectedClick?.(value);
|
|
17798
|
-
form.trigger(name);
|
|
17833
|
+
const handleInputChange = event => {
|
|
17834
|
+
setInputValue(event.target.value);
|
|
17799
17835
|
};
|
|
17800
|
-
const
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
17804
|
-
|
|
17805
|
-
|
|
17806
|
-
|
|
17807
|
-
const label = optionsWithKey[selectedValue]?.label;
|
|
17808
|
-
setRawInput(label ? String(label) : null);
|
|
17809
|
-
return;
|
|
17810
|
-
}
|
|
17811
|
-
setRawInput(null);
|
|
17836
|
+
const handleSelectedClick = event => {
|
|
17837
|
+
event.stopPropagation();
|
|
17838
|
+
};
|
|
17839
|
+
const handleRemoveSelectedClick = selectedItem => event => {
|
|
17840
|
+
event.stopPropagation();
|
|
17841
|
+
handleChange(selectedItem);
|
|
17842
|
+
onRemoveSelectedClick?.(selectedItem);
|
|
17812
17843
|
};
|
|
17813
|
-
const status = (() => {
|
|
17814
|
-
if (form.formState.errors[name]) return 'error';
|
|
17815
|
-
if (error) return 'error';
|
|
17816
|
-
if (success) return 'success';
|
|
17817
|
-
return 'basic';
|
|
17818
|
-
})();
|
|
17819
17844
|
return {
|
|
17820
17845
|
isOpen,
|
|
17821
17846
|
isDisabled,
|
|
@@ -17836,18 +17861,18 @@ const useTypeahead = ({
|
|
|
17836
17861
|
inputValue,
|
|
17837
17862
|
validationSchema,
|
|
17838
17863
|
status,
|
|
17839
|
-
error: error ?? form.formState.errors[name],
|
|
17840
17864
|
placeholder,
|
|
17841
17865
|
options: items,
|
|
17842
|
-
useFormResult
|
|
17866
|
+
useFormResult,
|
|
17843
17867
|
register,
|
|
17844
17868
|
setValue,
|
|
17845
|
-
|
|
17869
|
+
handleChange,
|
|
17846
17870
|
handleClearAll,
|
|
17847
17871
|
handleOpenChange,
|
|
17848
17872
|
handleInputChange,
|
|
17849
17873
|
handleInputClick,
|
|
17850
17874
|
handleInputKeyDown,
|
|
17875
|
+
handleSelectedClick,
|
|
17851
17876
|
handleRemoveSelectedClick
|
|
17852
17877
|
};
|
|
17853
17878
|
};
|
|
@@ -17961,7 +17986,7 @@ const MultipleTrigger = () => {
|
|
|
17961
17986
|
const theme = (0,react_namespaceObject.useTheme)();
|
|
17962
17987
|
const context = useTypeaheadContext();
|
|
17963
17988
|
const typeaheadInputAdditionalProps = {};
|
|
17964
|
-
if (!context.selectedItems.length &&
|
|
17989
|
+
if (!context.selectedItems.length && !!context.placeholder) {
|
|
17965
17990
|
typeaheadInputAdditionalProps.placeholder = context.placeholder;
|
|
17966
17991
|
}
|
|
17967
17992
|
return (0,jsx_runtime_namespaceObject.jsxs)((external_react_default()).Fragment, {
|
|
@@ -17969,7 +17994,7 @@ const MultipleTrigger = () => {
|
|
|
17969
17994
|
const currentOption = context.optionsWithKey[selectedItem];
|
|
17970
17995
|
const optionText = currentOption ? currentOption.children || currentOption.label || currentOption.value : '';
|
|
17971
17996
|
return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadItem, {
|
|
17972
|
-
onClick:
|
|
17997
|
+
onClick: context.handleSelectedClick,
|
|
17973
17998
|
isDisabled: context.isDisabled,
|
|
17974
17999
|
children: [(0,jsx_runtime_namespaceObject.jsx)(TypeaheadItemLabel, {
|
|
17975
18000
|
isDisabled: context.isDisabled,
|
|
@@ -18044,7 +18069,7 @@ const SingleTrigger = () => {
|
|
|
18044
18069
|
const context = useTypeaheadContext();
|
|
18045
18070
|
const theme = (0,react_namespaceObject.useTheme)();
|
|
18046
18071
|
const typeaheadInputAdditionalProps = {};
|
|
18047
|
-
if (!context.selectedItems.length &&
|
|
18072
|
+
if (!context.selectedItems.length && !!context.placeholder) {
|
|
18048
18073
|
typeaheadInputAdditionalProps.placeholder = context.placeholder;
|
|
18049
18074
|
}
|
|
18050
18075
|
return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadInputsGroupWrapper, {
|
|
@@ -18184,7 +18209,6 @@ const Typeahead = ({
|
|
|
18184
18209
|
name = 'typeahead-search',
|
|
18185
18210
|
label,
|
|
18186
18211
|
selectedItems,
|
|
18187
|
-
defaultSelectedItems,
|
|
18188
18212
|
isOpen,
|
|
18189
18213
|
isDisabled,
|
|
18190
18214
|
isMultiple,
|
|
@@ -18202,6 +18226,8 @@ const Typeahead = ({
|
|
|
18202
18226
|
optionsClassName,
|
|
18203
18227
|
wrapperClassName,
|
|
18204
18228
|
width = 300,
|
|
18229
|
+
setValue,
|
|
18230
|
+
register,
|
|
18205
18231
|
onChange,
|
|
18206
18232
|
onEmptyChange,
|
|
18207
18233
|
onClearAll,
|
|
@@ -18212,7 +18238,6 @@ const Typeahead = ({
|
|
|
18212
18238
|
const hookResult = useTypeahead({
|
|
18213
18239
|
name,
|
|
18214
18240
|
selectedItems,
|
|
18215
|
-
defaultSelectedItems,
|
|
18216
18241
|
isOpen,
|
|
18217
18242
|
isDisabled,
|
|
18218
18243
|
isMultiple,
|
|
@@ -18226,6 +18251,8 @@ const Typeahead = ({
|
|
|
18226
18251
|
success,
|
|
18227
18252
|
validationSchema,
|
|
18228
18253
|
placeholder,
|
|
18254
|
+
setValue,
|
|
18255
|
+
register,
|
|
18229
18256
|
onChange,
|
|
18230
18257
|
onEmptyChange,
|
|
18231
18258
|
renderOption,
|
|
@@ -18273,7 +18300,7 @@ const Typeahead = ({
|
|
|
18273
18300
|
status: hookResult.status,
|
|
18274
18301
|
disabled: isDisabled,
|
|
18275
18302
|
"data-testid": "helper-text",
|
|
18276
|
-
children:
|
|
18303
|
+
children: error ? error?.message : helperText
|
|
18277
18304
|
})]
|
|
18278
18305
|
})
|
|
18279
18306
|
});
|
|
@@ -19151,7 +19178,6 @@ const SelectWidget = props => {
|
|
|
19151
19178
|
placeholder,
|
|
19152
19179
|
onChange,
|
|
19153
19180
|
onBlur,
|
|
19154
|
-
onFocus,
|
|
19155
19181
|
onChangeOverride,
|
|
19156
19182
|
value
|
|
19157
19183
|
} = props;
|
|
@@ -19166,44 +19192,43 @@ const SelectWidget = props => {
|
|
|
19166
19192
|
const handleBlur = ({
|
|
19167
19193
|
target
|
|
19168
19194
|
}) => onBlur(id, target && target.value);
|
|
19169
|
-
const handleFocus = ({
|
|
19170
|
-
target
|
|
19171
|
-
}) => onFocus(id, target && target.value);
|
|
19172
19195
|
const onEmptyChange = isEmpty => {
|
|
19173
19196
|
if (isEmpty) {
|
|
19174
19197
|
handleChange();
|
|
19175
19198
|
}
|
|
19176
19199
|
};
|
|
19200
|
+
const register = fieldName => ({
|
|
19201
|
+
onBlur: handleBlur,
|
|
19202
|
+
onChange: handleChange,
|
|
19203
|
+
name: fieldName,
|
|
19204
|
+
ref: () => {}
|
|
19205
|
+
});
|
|
19177
19206
|
const items = Array.isArray(enumOptions) ? enumOptions : [];
|
|
19178
19207
|
const selectedItems = selectedIndex ? [items[Number(selectedIndex)].value] : [];
|
|
19179
|
-
return (0,jsx_runtime_namespaceObject.jsx)(
|
|
19180
|
-
|
|
19181
|
-
|
|
19182
|
-
|
|
19183
|
-
|
|
19184
|
-
|
|
19185
|
-
|
|
19186
|
-
|
|
19187
|
-
|
|
19188
|
-
|
|
19189
|
-
|
|
19190
|
-
|
|
19191
|
-
|
|
19192
|
-
|
|
19193
|
-
|
|
19194
|
-
|
|
19195
|
-
|
|
19196
|
-
|
|
19197
|
-
|
|
19198
|
-
|
|
19199
|
-
|
|
19200
|
-
|
|
19201
|
-
|
|
19202
|
-
|
|
19203
|
-
isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
|
|
19204
|
-
children: label || value
|
|
19205
|
-
}, value))
|
|
19206
|
-
})
|
|
19208
|
+
return (0,jsx_runtime_namespaceObject.jsx)(Typeahead, {
|
|
19209
|
+
width: "100%",
|
|
19210
|
+
selectedItems: selectedItems,
|
|
19211
|
+
isDisabled: disabled,
|
|
19212
|
+
name: name
|
|
19213
|
+
// RJSF provides placeholder as empty string
|
|
19214
|
+
,
|
|
19215
|
+
placeholder: placeholder || undefined,
|
|
19216
|
+
onChange: handleChange,
|
|
19217
|
+
register: register,
|
|
19218
|
+
onEmptyChange: onEmptyChange,
|
|
19219
|
+
renderOption: ({
|
|
19220
|
+
label,
|
|
19221
|
+
input
|
|
19222
|
+
}) => highlightInputMatch(label, input),
|
|
19223
|
+
children: items.map(({
|
|
19224
|
+
label,
|
|
19225
|
+
value
|
|
19226
|
+
}) => (0,jsx_runtime_namespaceObject.jsx)(TypeaheadOption_TypeaheadOption, {
|
|
19227
|
+
value: value,
|
|
19228
|
+
label: label || value,
|
|
19229
|
+
isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
|
|
19230
|
+
children: label || value
|
|
19231
|
+
}, value))
|
|
19207
19232
|
});
|
|
19208
19233
|
};
|
|
19209
19234
|
;// ./src/components/JsonSchemaForm/widgets/PasswordWidget.tsx
|