@ssa-ui-kit/core 2.16.1 → 2.16.2-canary-1c17e94-20250507
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/DateRangePicker/types.d.ts +2 -1
- 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 +5 -4
- package/dist/components/Typeahead/useTypeahead.d.ts +16 -15
- package/dist/index.js +247 -271
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -11678,7 +11678,7 @@ const Trigger = () => {
|
|
|
11678
11678
|
name: "carrot-right",
|
|
11679
11679
|
size: 18,
|
|
11680
11680
|
color: theme.colors.greyDarker80,
|
|
11681
|
-
className: classNames?.trigger?.
|
|
11681
|
+
className: classNames?.trigger?.arrowIcon,
|
|
11682
11682
|
css: Trigger_ref
|
|
11683
11683
|
}), (0,jsx_runtime_namespaceObject.jsx)(TriggerInput, {
|
|
11684
11684
|
datepickerType: "to",
|
|
@@ -11699,6 +11699,7 @@ const Trigger = () => {
|
|
|
11699
11699
|
variant: "tertiary",
|
|
11700
11700
|
"aria-label": "Calendar",
|
|
11701
11701
|
isDisabled: disabled,
|
|
11702
|
+
className: classNames?.trigger?.calendarIcon,
|
|
11702
11703
|
css: /*#__PURE__*/(0,react_namespaceObject.css)({
|
|
11703
11704
|
padding: 0,
|
|
11704
11705
|
margin: '0 8px 0 14px',
|
|
@@ -17522,6 +17523,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17522
17523
|
options: [],
|
|
17523
17524
|
placeholder: '',
|
|
17524
17525
|
useFormResult: {},
|
|
17526
|
+
error: undefined,
|
|
17525
17527
|
setValue: () => {
|
|
17526
17528
|
/* no-op */
|
|
17527
17529
|
},
|
|
@@ -17529,7 +17531,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17529
17531
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
17530
17532
|
return {};
|
|
17531
17533
|
},
|
|
17532
|
-
|
|
17534
|
+
onChange: () => {
|
|
17533
17535
|
/* no-op */
|
|
17534
17536
|
},
|
|
17535
17537
|
handleClearAll: () => {
|
|
@@ -17549,9 +17551,6 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17549
17551
|
},
|
|
17550
17552
|
handleRemoveSelectedClick: () => () => {
|
|
17551
17553
|
/* no-op */
|
|
17552
|
-
},
|
|
17553
|
-
handleSelectedClick: () => {
|
|
17554
|
-
/* no-op */
|
|
17555
17554
|
}
|
|
17556
17555
|
});
|
|
17557
17556
|
const useTypeaheadContext = () => external_react_namespaceObject.useContext(TypeaheadContext);
|
|
@@ -17559,10 +17558,18 @@ const useTypeaheadContext = () => external_react_namespaceObject.useContext(Type
|
|
|
17559
17558
|
|
|
17560
17559
|
|
|
17561
17560
|
|
|
17561
|
+
const findExactMatch = (input, options) => {
|
|
17562
|
+
const normalizedInput = input.toLowerCase();
|
|
17563
|
+
return Object.values(options).find(opt => {
|
|
17564
|
+
const labelText = (opt.label ?? opt.value).toString().toLowerCase();
|
|
17565
|
+
return labelText === normalizedInput;
|
|
17566
|
+
});
|
|
17567
|
+
};
|
|
17562
17568
|
const useTypeahead = ({
|
|
17563
17569
|
name = 'typeahead-input',
|
|
17564
17570
|
isOpen: isInitOpen,
|
|
17565
|
-
selectedItems,
|
|
17571
|
+
selectedItems: providedSelectedItems,
|
|
17572
|
+
defaultSelectedItems,
|
|
17566
17573
|
isDisabled,
|
|
17567
17574
|
isMultiple,
|
|
17568
17575
|
children,
|
|
@@ -17575,8 +17582,8 @@ const useTypeahead = ({
|
|
|
17575
17582
|
error,
|
|
17576
17583
|
success,
|
|
17577
17584
|
placeholder,
|
|
17578
|
-
|
|
17579
|
-
|
|
17585
|
+
filterOptions = true,
|
|
17586
|
+
autoSelect = true,
|
|
17580
17587
|
onChange,
|
|
17581
17588
|
onClearAll,
|
|
17582
17589
|
onRemoveSelectedClick,
|
|
@@ -17584,271 +17591,250 @@ const useTypeahead = ({
|
|
|
17584
17591
|
renderOption
|
|
17585
17592
|
}) => {
|
|
17586
17593
|
const inputName = `${name}-text`;
|
|
17587
|
-
const
|
|
17588
|
-
const
|
|
17589
|
-
const
|
|
17590
|
-
|
|
17591
|
-
|
|
17592
|
-
|
|
17593
|
-
|
|
17594
|
-
const
|
|
17595
|
-
const
|
|
17596
|
-
|
|
17597
|
-
|
|
17598
|
-
const triggerRef = (0,external_react_namespaceObject.useRef)(null);
|
|
17599
|
-
const useFormResult = (0,external_react_hook_form_namespaceObject.useForm)();
|
|
17600
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17601
|
-
if (!register) {
|
|
17602
|
-
console.warn('Typeahead component must be used within a Form component');
|
|
17603
|
-
}
|
|
17604
|
-
}, []);
|
|
17605
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17606
|
-
if (isMultiple) {
|
|
17607
|
-
setValue?.(name, selected, {
|
|
17608
|
-
shouldDirty: !isFirstRender
|
|
17609
|
-
});
|
|
17610
|
-
setInputValue('');
|
|
17611
|
-
setFirstSuggestion('');
|
|
17612
|
-
} else {
|
|
17613
|
-
setValue?.(name, selected.length ? selected[0] : [], {
|
|
17614
|
-
shouldDirty: !isFirstRender
|
|
17615
|
-
});
|
|
17594
|
+
const defaultForm = (0,external_react_hook_form_namespaceObject.useForm)();
|
|
17595
|
+
const form = (0,external_react_hook_form_namespaceObject.useFormContext)() ?? defaultForm;
|
|
17596
|
+
const {
|
|
17597
|
+
register,
|
|
17598
|
+
setValue,
|
|
17599
|
+
watch
|
|
17600
|
+
} = form;
|
|
17601
|
+
const formFieldValue = watch(name);
|
|
17602
|
+
const controlledValue = (() => {
|
|
17603
|
+
if (providedSelectedItems) {
|
|
17604
|
+
return providedSelectedItems;
|
|
17616
17605
|
}
|
|
17617
|
-
|
|
17618
|
-
|
|
17619
|
-
|
|
17620
|
-
if (isDisabled && isOpen) {
|
|
17621
|
-
setIsOpen(false);
|
|
17606
|
+
// controlledValue should be undefined if defaultSelectedItems is provided
|
|
17607
|
+
if (defaultSelectedItems) {
|
|
17608
|
+
return;
|
|
17622
17609
|
}
|
|
17623
|
-
|
|
17624
|
-
|
|
17625
|
-
const status = success ? 'success' : useFormResult.formState.errors[name] ? 'error' : 'basic';
|
|
17626
|
-
setStatus(status);
|
|
17627
|
-
}, [useFormResult.formState.errors[name], success]);
|
|
17628
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17629
|
-
if (error) {
|
|
17630
|
-
useFormResult.setError(name, error);
|
|
17631
|
-
} else {
|
|
17632
|
-
setStatus('basic');
|
|
17633
|
-
useFormResult.resetField(name);
|
|
17610
|
+
if (isMultiple) {
|
|
17611
|
+
return Array.isArray(formFieldValue) ? formFieldValue : [];
|
|
17634
17612
|
}
|
|
17635
|
-
|
|
17636
|
-
|
|
17637
|
-
|
|
17638
|
-
|
|
17613
|
+
return ['number', 'string'].includes(typeof formFieldValue) ? [formFieldValue] : [];
|
|
17614
|
+
})();
|
|
17615
|
+
const [isOpen, _setIsOpen] = (0,hooks_namespaceObject.useUncontrolled)({
|
|
17616
|
+
defaultValue: isInitOpen,
|
|
17617
|
+
finalValue: false
|
|
17618
|
+
});
|
|
17619
|
+
const [selectedItems, setSelected] = (0,hooks_namespaceObject.useUncontrolled)({
|
|
17620
|
+
value: controlledValue,
|
|
17621
|
+
defaultValue: defaultSelectedItems,
|
|
17622
|
+
finalValue: []
|
|
17623
|
+
});
|
|
17624
|
+
const [rawInput, setRawInput] = (0,external_react_namespaceObject.useState)(null);
|
|
17625
|
+
const {
|
|
17626
|
+
ref: inputRef
|
|
17627
|
+
} = (0,hooks_namespaceObject.useElementSize)();
|
|
17628
|
+
const triggerRef = (0,external_react_namespaceObject.useRef)(null);
|
|
17629
|
+
(0,external_react_hook_form_namespaceObject.useController)({
|
|
17630
|
+
name,
|
|
17631
|
+
rules: validationSchema,
|
|
17632
|
+
defaultValue: isMultiple ? selectedItems : selectedItems[0]
|
|
17633
|
+
});
|
|
17634
|
+
const typeaheadId = (0,external_react_namespaceObject.useId)();
|
|
17635
|
+
const optionsWithKey = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17636
|
+
const opts = {};
|
|
17637
|
+
external_react_default().Children.forEach(children, child => {
|
|
17638
|
+
if (/*#__PURE__*/external_react_default().isValidElement(child)) {
|
|
17639
|
+
opts[child.props.value] = child.props;
|
|
17640
|
+
}
|
|
17639
17641
|
});
|
|
17642
|
+
return opts;
|
|
17640
17643
|
}, [children]);
|
|
17641
|
-
(0,external_react_namespaceObject.
|
|
17642
|
-
|
|
17643
|
-
if (
|
|
17644
|
-
|
|
17645
|
-
|
|
17646
|
-
|
|
17647
|
-
|
|
17648
|
-
|
|
17649
|
-
|
|
17650
|
-
|
|
17651
|
-
|
|
17652
|
-
|
|
17653
|
-
|
|
17654
|
-
|
|
17644
|
+
const inputValue = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17645
|
+
if (isMultiple) return rawInput ?? '';
|
|
17646
|
+
if (rawInput != null) return rawInput;
|
|
17647
|
+
return selectedItems.length === 1 ? optionsWithKey[selectedItems[0]]?.label?.toString() || '' : '';
|
|
17648
|
+
}, [isMultiple, rawInput, selectedItems, optionsWithKey]);
|
|
17649
|
+
const filteredChildren = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17650
|
+
// if filtering is disabled, or there's no input, show all
|
|
17651
|
+
if (!filterOptions || !inputValue) return external_react_default().Children.toArray(children);
|
|
17652
|
+
const needle = inputValue.toLowerCase();
|
|
17653
|
+
return external_react_default().Children.toArray(children).filter(child => {
|
|
17654
|
+
if (! /*#__PURE__*/external_react_default().isValidElement(child)) return false;
|
|
17655
|
+
const {
|
|
17656
|
+
label,
|
|
17657
|
+
value
|
|
17658
|
+
} = child.props;
|
|
17659
|
+
const text = (label ?? value)?.toString().toLowerCase() || '';
|
|
17660
|
+
return text.includes(needle);
|
|
17655
17661
|
});
|
|
17656
|
-
}, [
|
|
17657
|
-
(0,external_react_namespaceObject.
|
|
17658
|
-
|
|
17659
|
-
|
|
17660
|
-
|
|
17662
|
+
}, [children, inputValue]);
|
|
17663
|
+
const items = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17664
|
+
return filteredChildren.map((child, index) => {
|
|
17665
|
+
if (! /*#__PURE__*/external_react_default().isValidElement(child)) return null;
|
|
17666
|
+
const isActive = selectedItems.includes(child.props.value);
|
|
17661
17667
|
const {
|
|
17662
|
-
id,
|
|
17663
17668
|
value,
|
|
17664
17669
|
label,
|
|
17670
|
+
id,
|
|
17665
17671
|
isDisabled
|
|
17666
17672
|
} = child.props;
|
|
17667
|
-
const isActive = selected.includes(child.props.value);
|
|
17668
17673
|
return /*#__PURE__*/external_react_default().cloneElement(child, {
|
|
17669
|
-
index,
|
|
17670
17674
|
...child.props,
|
|
17675
|
+
index,
|
|
17671
17676
|
isActive,
|
|
17672
17677
|
isDisabled,
|
|
17673
|
-
|
|
17678
|
+
role: 'option',
|
|
17674
17679
|
'aria-selected': isActive,
|
|
17675
17680
|
'aria-labelledby': `typeahead-label-${name}`,
|
|
17676
|
-
|
|
17677
|
-
|
|
17678
|
-
event.preventDefault();
|
|
17681
|
+
onClick: e => {
|
|
17682
|
+
e.preventDefault();
|
|
17679
17683
|
if (!isDisabled) {
|
|
17680
|
-
|
|
17684
|
+
const shouldClose = !isMultiple;
|
|
17685
|
+
handleChange({
|
|
17686
|
+
value,
|
|
17687
|
+
shouldClose
|
|
17688
|
+
});
|
|
17681
17689
|
}
|
|
17682
17690
|
},
|
|
17683
|
-
children: renderOption
|
|
17691
|
+
children: renderOption?.({
|
|
17684
17692
|
value: id || value,
|
|
17685
|
-
input: inputValue
|
|
17693
|
+
input: inputValue,
|
|
17686
17694
|
label
|
|
17687
|
-
})
|
|
17695
|
+
}) ?? child.props.children ?? label ?? value
|
|
17688
17696
|
});
|
|
17689
17697
|
});
|
|
17690
|
-
|
|
17691
|
-
|
|
17692
|
-
|
|
17693
|
-
|
|
17694
|
-
|
|
17695
|
-
if (!
|
|
17696
|
-
|
|
17697
|
-
|
|
17698
|
-
|
|
17699
|
-
setSelected([foundItem.value]);
|
|
17698
|
+
}, [children, selectedItems, inputValue]);
|
|
17699
|
+
const firstSuggestion = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17700
|
+
if (!inputValue) return '';
|
|
17701
|
+
const needle = inputValue.toLowerCase();
|
|
17702
|
+
for (const child of filteredChildren) {
|
|
17703
|
+
if (! /*#__PURE__*/external_react_default().isValidElement(child)) continue;
|
|
17704
|
+
const labelText = (child.props.label ?? child.props.value).toString();
|
|
17705
|
+
if (labelText.toLowerCase().startsWith(needle)) {
|
|
17706
|
+
return inputValue + labelText.slice(inputValue.length);
|
|
17700
17707
|
}
|
|
17701
17708
|
}
|
|
17702
|
-
|
|
17703
|
-
|
|
17704
|
-
|
|
17705
|
-
|
|
17706
|
-
|
|
17707
|
-
});
|
|
17708
|
-
}, [selected]);
|
|
17709
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17710
|
-
if (inputValue) {
|
|
17711
|
-
const newFirstSuggestion = Object.values(optionsWithKey)?.find(item => {
|
|
17712
|
-
const label = (0,utils_namespaceObject.propOr)('', 'label')(item);
|
|
17713
|
-
return label.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
17714
|
-
});
|
|
17715
|
-
const firstSuggestionLabel = (0,utils_namespaceObject.propOr)('', 'label')(newFirstSuggestion);
|
|
17716
|
-
const humanSuggestionLabel = inputValue.concat(firstSuggestionLabel.slice(inputValue.length));
|
|
17717
|
-
setFirstSuggestion(humanSuggestionLabel);
|
|
17718
|
-
} else {
|
|
17719
|
-
setFirstSuggestion('');
|
|
17720
|
-
if (isMultiple) {
|
|
17721
|
-
setInputValue('');
|
|
17722
|
-
}
|
|
17723
|
-
}
|
|
17724
|
-
}, [inputValue, items, selected]);
|
|
17725
|
-
const processSingleSelected = ({
|
|
17726
|
-
optionsWithKeyLocal = {},
|
|
17727
|
-
selectedLocal = []
|
|
17728
|
-
}) => {
|
|
17729
|
-
if (!isMultiple && selectedLocal.length && Object.keys(optionsWithKeyLocal).length) {
|
|
17730
|
-
const currentOption = optionsWithKeyLocal[selectedLocal[0]];
|
|
17731
|
-
const optionText = currentOption && (currentOption.children || currentOption.label || currentOption.value);
|
|
17732
|
-
setInputValue(`${optionText}`);
|
|
17709
|
+
return '';
|
|
17710
|
+
}, [inputValue, filteredChildren]);
|
|
17711
|
+
const setIsOpen = open => {
|
|
17712
|
+
if (!open) {
|
|
17713
|
+
form.trigger(name);
|
|
17733
17714
|
}
|
|
17715
|
+
_setIsOpen(open);
|
|
17734
17716
|
};
|
|
17735
|
-
const
|
|
17736
|
-
|
|
17717
|
+
const handleChange = ({
|
|
17718
|
+
value,
|
|
17719
|
+
shouldClose = true,
|
|
17720
|
+
resetInput = true
|
|
17737
17721
|
}) => {
|
|
17738
|
-
|
|
17739
|
-
const
|
|
17740
|
-
|
|
17741
|
-
|
|
17742
|
-
|
|
17743
|
-
|
|
17744
|
-
|
|
17745
|
-
|
|
17746
|
-
|
|
17747
|
-
|
|
17748
|
-
setOptionsWithKey(keyedOptions);
|
|
17749
|
-
setItems(childItems);
|
|
17750
|
-
processSingleSelected({
|
|
17751
|
-
optionsWithKeyLocal: keyedOptions,
|
|
17752
|
-
selectedLocal
|
|
17753
|
-
});
|
|
17754
|
-
setFirstRender(false);
|
|
17755
|
-
};
|
|
17756
|
-
const handleOnEmptyChange = newIsEmptyValue => {
|
|
17757
|
-
if (newIsEmptyValue !== isEmpty) {
|
|
17758
|
-
setIsEmpty(newIsEmptyValue);
|
|
17759
|
-
onEmptyChange?.(newIsEmptyValue);
|
|
17722
|
+
if (isDisabled || value == null) return;
|
|
17723
|
+
const alreadySelected = selectedItems.includes(value);
|
|
17724
|
+
const updatedSelected = isMultiple ? alreadySelected ? selectedItems.filter(item => item !== value) : [...selectedItems, value] : alreadySelected ? [] : [value];
|
|
17725
|
+
const fieldValue = isMultiple ? updatedSelected : updatedSelected[0];
|
|
17726
|
+
setSelected(updatedSelected);
|
|
17727
|
+
setValue?.(name, fieldValue);
|
|
17728
|
+
form.clearErrors(name);
|
|
17729
|
+
if (resetInput) {
|
|
17730
|
+
const rawInputValue = isMultiple ? null : updatedSelected.length ? String(optionsWithKey[value]?.label) : null;
|
|
17731
|
+
setRawInput(rawInputValue);
|
|
17760
17732
|
}
|
|
17761
|
-
|
|
17762
|
-
|
|
17763
|
-
if (!isDisabled) {
|
|
17764
|
-
setIsOpen(open);
|
|
17733
|
+
if (shouldClose) {
|
|
17734
|
+
setIsOpen(false);
|
|
17765
17735
|
}
|
|
17736
|
+
onChange?.(value, !alreadySelected);
|
|
17737
|
+
onEmptyChange?.(updatedSelected.length === 0);
|
|
17766
17738
|
};
|
|
17767
|
-
const
|
|
17768
|
-
if (isDisabled
|
|
17769
|
-
|
|
17770
|
-
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
if (isMultiple) {
|
|
17774
|
-
setSelected(currentSelected => isChangingItemSelected ? currentSelected.filter(current => current !== changingValue) : [...currentSelected, changingValue]);
|
|
17775
|
-
setInputValue('');
|
|
17776
|
-
} else {
|
|
17777
|
-
if (selected[0] === changingValue) {
|
|
17778
|
-
setSelected([]);
|
|
17779
|
-
setInputValue('');
|
|
17780
|
-
} else {
|
|
17781
|
-
setSelected([changingValue]);
|
|
17782
|
-
}
|
|
17783
|
-
}
|
|
17739
|
+
const handleClearAll = e => {
|
|
17740
|
+
if (isDisabled) return;
|
|
17741
|
+
e.preventDefault();
|
|
17742
|
+
e.stopPropagation();
|
|
17743
|
+
setSelected([]);
|
|
17744
|
+
setRawInput(null);
|
|
17784
17745
|
setIsOpen(false);
|
|
17785
|
-
|
|
17746
|
+
setValue?.(name, undefined);
|
|
17747
|
+
form.trigger(name);
|
|
17786
17748
|
inputRef.current?.focus();
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
useFormResult.trigger(name);
|
|
17790
|
-
onChange?.(changingValue, isNewSelected);
|
|
17749
|
+
onClearAll?.();
|
|
17750
|
+
onEmptyChange?.(true);
|
|
17791
17751
|
};
|
|
17792
|
-
const
|
|
17793
|
-
|
|
17752
|
+
const handleInputChange = e => {
|
|
17753
|
+
const input = e.target.value;
|
|
17754
|
+
setRawInput(input);
|
|
17755
|
+
if (!autoSelect || !filterOptions) return;
|
|
17756
|
+
const match = findExactMatch(input, optionsWithKey);
|
|
17757
|
+
if (match) {
|
|
17758
|
+
handleChange({
|
|
17759
|
+
value: match.value,
|
|
17760
|
+
shouldClose: false
|
|
17761
|
+
});
|
|
17794
17762
|
return;
|
|
17795
17763
|
}
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
|
|
17800
|
-
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
17804
|
-
onClearAll?.();
|
|
17764
|
+
// unset selected value if not fully matched
|
|
17765
|
+
if (!isMultiple && selectedItems.length > 0) {
|
|
17766
|
+
handleChange({
|
|
17767
|
+
value: selectedItems[0],
|
|
17768
|
+
shouldClose: false,
|
|
17769
|
+
resetInput: false
|
|
17770
|
+
});
|
|
17771
|
+
}
|
|
17805
17772
|
};
|
|
17806
|
-
const handleInputClick =
|
|
17773
|
+
const handleInputClick = e => {
|
|
17774
|
+
e.stopPropagation();
|
|
17775
|
+
e.preventDefault();
|
|
17807
17776
|
if (!isDisabled) {
|
|
17808
17777
|
inputRef.current?.focus();
|
|
17809
17778
|
setIsOpen(true);
|
|
17810
17779
|
}
|
|
17811
|
-
event.stopPropagation();
|
|
17812
|
-
event.preventDefault();
|
|
17813
17780
|
};
|
|
17814
|
-
const handleInputKeyDown =
|
|
17815
|
-
|
|
17816
|
-
|
|
17817
|
-
|
|
17818
|
-
|
|
17819
|
-
|
|
17820
|
-
|
|
17821
|
-
|
|
17822
|
-
handleChange(foundItem?.value);
|
|
17823
|
-
if (foundItem) {
|
|
17824
|
-
setInputValue(`${foundItem?.label}`);
|
|
17781
|
+
const handleInputKeyDown = e => {
|
|
17782
|
+
const isEnterOrTab = ['Enter', 'Tab'].includes(e.code);
|
|
17783
|
+
if (isEnterOrTab && firstSuggestion && firstSuggestion !== inputValue) {
|
|
17784
|
+
const match = findExactMatch(firstSuggestion, optionsWithKey);
|
|
17785
|
+
if (match) {
|
|
17786
|
+
handleChange({
|
|
17787
|
+
value: match.value
|
|
17788
|
+
});
|
|
17825
17789
|
}
|
|
17826
|
-
|
|
17827
|
-
return
|
|
17828
|
-
}
|
|
17829
|
-
|
|
17830
|
-
|
|
17831
|
-
|
|
17832
|
-
|
|
17790
|
+
e.preventDefault();
|
|
17791
|
+
return;
|
|
17792
|
+
}
|
|
17793
|
+
if (isMultiple && e.code === 'Backspace' && selectedItems.length && !inputValue) {
|
|
17794
|
+
const lastSelected = selectedItems[selectedItems.length - 1];
|
|
17795
|
+
handleChange({
|
|
17796
|
+
value: lastSelected,
|
|
17797
|
+
shouldClose: false
|
|
17798
|
+
});
|
|
17799
|
+
e.preventDefault();
|
|
17800
|
+
return;
|
|
17801
|
+
}
|
|
17802
|
+
if (!isOpen && firstSuggestion !== inputValue) {
|
|
17833
17803
|
setIsOpen(true);
|
|
17834
17804
|
}
|
|
17835
17805
|
};
|
|
17836
|
-
const
|
|
17837
|
-
|
|
17838
|
-
|
|
17839
|
-
|
|
17840
|
-
|
|
17806
|
+
const handleRemoveSelectedClick = value => e => {
|
|
17807
|
+
e.stopPropagation();
|
|
17808
|
+
handleChange({
|
|
17809
|
+
value
|
|
17810
|
+
});
|
|
17811
|
+
onRemoveSelectedClick?.(value);
|
|
17812
|
+
form.trigger(name);
|
|
17841
17813
|
};
|
|
17842
|
-
const
|
|
17843
|
-
|
|
17844
|
-
|
|
17845
|
-
|
|
17814
|
+
const handleOpenChange = (open, event, reason) => {
|
|
17815
|
+
if (isDisabled || reason === 'reference-press') {
|
|
17816
|
+
return;
|
|
17817
|
+
}
|
|
17818
|
+
setIsOpen(open);
|
|
17819
|
+
if (!isMultiple && selectedItems.length > 0) {
|
|
17820
|
+
const selectedValue = selectedItems[0];
|
|
17821
|
+
const label = optionsWithKey[selectedValue]?.label;
|
|
17822
|
+
setRawInput(label ? String(label) : null);
|
|
17823
|
+
return;
|
|
17824
|
+
}
|
|
17825
|
+
setRawInput(null);
|
|
17846
17826
|
};
|
|
17827
|
+
const status = (() => {
|
|
17828
|
+
if (form.formState.errors[name]) return 'error';
|
|
17829
|
+
if (error) return 'error';
|
|
17830
|
+
if (success) return 'success';
|
|
17831
|
+
return 'basic';
|
|
17832
|
+
})();
|
|
17847
17833
|
return {
|
|
17848
17834
|
isOpen,
|
|
17849
17835
|
isDisabled,
|
|
17850
17836
|
optionsWithKey,
|
|
17851
|
-
selectedItems
|
|
17837
|
+
selectedItems,
|
|
17852
17838
|
inputRef,
|
|
17853
17839
|
firstSuggestion,
|
|
17854
17840
|
isMultiple,
|
|
@@ -17864,18 +17850,18 @@ const useTypeahead = ({
|
|
|
17864
17850
|
inputValue,
|
|
17865
17851
|
validationSchema,
|
|
17866
17852
|
status,
|
|
17853
|
+
error: error ?? form.formState.errors[name],
|
|
17867
17854
|
placeholder,
|
|
17868
17855
|
options: items,
|
|
17869
|
-
useFormResult,
|
|
17856
|
+
useFormResult: form,
|
|
17870
17857
|
register,
|
|
17871
17858
|
setValue,
|
|
17872
|
-
|
|
17859
|
+
onChange,
|
|
17873
17860
|
handleClearAll,
|
|
17874
17861
|
handleOpenChange,
|
|
17875
17862
|
handleInputChange,
|
|
17876
17863
|
handleInputClick,
|
|
17877
17864
|
handleInputKeyDown,
|
|
17878
|
-
handleSelectedClick,
|
|
17879
17865
|
handleRemoveSelectedClick
|
|
17880
17866
|
};
|
|
17881
17867
|
};
|
|
@@ -17989,7 +17975,7 @@ const MultipleTrigger = () => {
|
|
|
17989
17975
|
const theme = (0,react_namespaceObject.useTheme)();
|
|
17990
17976
|
const context = useTypeaheadContext();
|
|
17991
17977
|
const typeaheadInputAdditionalProps = {};
|
|
17992
|
-
if (!context.selectedItems.length && !!context.placeholder) {
|
|
17978
|
+
if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
|
|
17993
17979
|
typeaheadInputAdditionalProps.placeholder = context.placeholder;
|
|
17994
17980
|
}
|
|
17995
17981
|
return (0,jsx_runtime_namespaceObject.jsxs)((external_react_default()).Fragment, {
|
|
@@ -17997,7 +17983,7 @@ const MultipleTrigger = () => {
|
|
|
17997
17983
|
const currentOption = context.optionsWithKey[selectedItem];
|
|
17998
17984
|
const optionText = currentOption ? currentOption.children || currentOption.label || currentOption.value : '';
|
|
17999
17985
|
return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadItem, {
|
|
18000
|
-
onClick:
|
|
17986
|
+
onClick: e => e.stopPropagation(),
|
|
18001
17987
|
isDisabled: context.isDisabled,
|
|
18002
17988
|
children: [(0,jsx_runtime_namespaceObject.jsx)(TypeaheadItemLabel, {
|
|
18003
17989
|
isDisabled: context.isDisabled,
|
|
@@ -18041,11 +18027,6 @@ const MultipleTrigger = () => {
|
|
|
18041
18027
|
disabled: context.isDisabled,
|
|
18042
18028
|
className: ['typeahead-input', TypeaheadInput(theme), TypeaheadInputPlaceholder].join(' '),
|
|
18043
18029
|
...typeaheadInputAdditionalProps
|
|
18044
|
-
}), (0,jsx_runtime_namespaceObject.jsx)("input", {
|
|
18045
|
-
type: "hidden",
|
|
18046
|
-
readOnly: true,
|
|
18047
|
-
value: context.selectedItems,
|
|
18048
|
-
...context.register?.(context.name, context.validationSchema)
|
|
18049
18030
|
})]
|
|
18050
18031
|
}), !context.isDisabled && context.selectedItems.length ? (0,jsx_runtime_namespaceObject.jsx)(Button_Button, {
|
|
18051
18032
|
variant: "tertiary",
|
|
@@ -18072,7 +18053,7 @@ const SingleTrigger = () => {
|
|
|
18072
18053
|
const context = useTypeaheadContext();
|
|
18073
18054
|
const theme = (0,react_namespaceObject.useTheme)();
|
|
18074
18055
|
const typeaheadInputAdditionalProps = {};
|
|
18075
|
-
if (!context.selectedItems.length && !!context.placeholder) {
|
|
18056
|
+
if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
|
|
18076
18057
|
typeaheadInputAdditionalProps.placeholder = context.placeholder;
|
|
18077
18058
|
}
|
|
18078
18059
|
return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadInputsGroupWrapper, {
|
|
@@ -18101,11 +18082,6 @@ const SingleTrigger = () => {
|
|
|
18101
18082
|
tabIndex: -1,
|
|
18102
18083
|
className: ['typeahead-input', TypeaheadInput(theme), TypeaheadInputPlaceholder].join(' '),
|
|
18103
18084
|
...typeaheadInputAdditionalProps
|
|
18104
|
-
}), (0,jsx_runtime_namespaceObject.jsx)("input", {
|
|
18105
|
-
type: "hidden",
|
|
18106
|
-
readOnly: true,
|
|
18107
|
-
value: context.selectedItems[0] || '',
|
|
18108
|
-
...context.register?.(context.name, context.validationSchema)
|
|
18109
18085
|
}), !context.isDisabled && context.selectedItems.length ? (0,jsx_runtime_namespaceObject.jsx)(Button_Button, {
|
|
18110
18086
|
variant: "tertiary",
|
|
18111
18087
|
"data-testid": "remove-all-button",
|
|
@@ -18212,6 +18188,7 @@ const Typeahead = ({
|
|
|
18212
18188
|
name = 'typeahead-search',
|
|
18213
18189
|
label,
|
|
18214
18190
|
selectedItems,
|
|
18191
|
+
defaultSelectedItems,
|
|
18215
18192
|
isOpen,
|
|
18216
18193
|
isDisabled,
|
|
18217
18194
|
isMultiple,
|
|
@@ -18229,8 +18206,6 @@ const Typeahead = ({
|
|
|
18229
18206
|
optionsClassName,
|
|
18230
18207
|
wrapperClassName,
|
|
18231
18208
|
width = 300,
|
|
18232
|
-
setValue,
|
|
18233
|
-
register,
|
|
18234
18209
|
onChange,
|
|
18235
18210
|
onEmptyChange,
|
|
18236
18211
|
onClearAll,
|
|
@@ -18241,6 +18216,7 @@ const Typeahead = ({
|
|
|
18241
18216
|
const hookResult = useTypeahead({
|
|
18242
18217
|
name,
|
|
18243
18218
|
selectedItems,
|
|
18219
|
+
defaultSelectedItems,
|
|
18244
18220
|
isOpen,
|
|
18245
18221
|
isDisabled,
|
|
18246
18222
|
isMultiple,
|
|
@@ -18254,8 +18230,6 @@ const Typeahead = ({
|
|
|
18254
18230
|
success,
|
|
18255
18231
|
validationSchema,
|
|
18256
18232
|
placeholder,
|
|
18257
|
-
setValue,
|
|
18258
|
-
register,
|
|
18259
18233
|
onChange,
|
|
18260
18234
|
onEmptyChange,
|
|
18261
18235
|
renderOption,
|
|
@@ -18303,7 +18277,7 @@ const Typeahead = ({
|
|
|
18303
18277
|
status: hookResult.status,
|
|
18304
18278
|
disabled: isDisabled,
|
|
18305
18279
|
"data-testid": "helper-text",
|
|
18306
|
-
children: error ? error?.message : helperText
|
|
18280
|
+
children: hookResult.error ? hookResult.error?.message?.toString() : helperText
|
|
18307
18281
|
})]
|
|
18308
18282
|
})
|
|
18309
18283
|
});
|
|
@@ -19181,6 +19155,7 @@ const SelectWidget = props => {
|
|
|
19181
19155
|
placeholder,
|
|
19182
19156
|
onChange,
|
|
19183
19157
|
onBlur,
|
|
19158
|
+
onFocus,
|
|
19184
19159
|
onChangeOverride,
|
|
19185
19160
|
value
|
|
19186
19161
|
} = props;
|
|
@@ -19195,43 +19170,44 @@ const SelectWidget = props => {
|
|
|
19195
19170
|
const handleBlur = ({
|
|
19196
19171
|
target
|
|
19197
19172
|
}) => onBlur(id, target && target.value);
|
|
19173
|
+
const handleFocus = ({
|
|
19174
|
+
target
|
|
19175
|
+
}) => onFocus(id, target && target.value);
|
|
19198
19176
|
const onEmptyChange = isEmpty => {
|
|
19199
19177
|
if (isEmpty) {
|
|
19200
19178
|
handleChange();
|
|
19201
19179
|
}
|
|
19202
19180
|
};
|
|
19203
|
-
const register = fieldName => ({
|
|
19204
|
-
onBlur: handleBlur,
|
|
19205
|
-
onChange: handleChange,
|
|
19206
|
-
name: fieldName,
|
|
19207
|
-
ref: () => {}
|
|
19208
|
-
});
|
|
19209
19181
|
const items = Array.isArray(enumOptions) ? enumOptions : [];
|
|
19210
19182
|
const selectedItems = selectedIndex ? [items[Number(selectedIndex)].value] : [];
|
|
19211
|
-
return (0,jsx_runtime_namespaceObject.jsx)(
|
|
19212
|
-
|
|
19213
|
-
|
|
19214
|
-
|
|
19215
|
-
|
|
19216
|
-
|
|
19217
|
-
|
|
19218
|
-
|
|
19219
|
-
|
|
19220
|
-
|
|
19221
|
-
|
|
19222
|
-
|
|
19223
|
-
|
|
19224
|
-
|
|
19225
|
-
|
|
19226
|
-
|
|
19227
|
-
|
|
19228
|
-
|
|
19229
|
-
|
|
19230
|
-
|
|
19231
|
-
|
|
19232
|
-
|
|
19233
|
-
|
|
19234
|
-
|
|
19183
|
+
return (0,jsx_runtime_namespaceObject.jsx)("div", {
|
|
19184
|
+
id: id,
|
|
19185
|
+
onBlur: handleBlur,
|
|
19186
|
+
onFocus: handleFocus,
|
|
19187
|
+
children: (0,jsx_runtime_namespaceObject.jsx)(Typeahead, {
|
|
19188
|
+
width: "100%",
|
|
19189
|
+
selectedItems: selectedItems,
|
|
19190
|
+
isDisabled: disabled,
|
|
19191
|
+
name: name
|
|
19192
|
+
// RJSF provides placeholder as empty string
|
|
19193
|
+
,
|
|
19194
|
+
placeholder: placeholder || undefined,
|
|
19195
|
+
onChange: handleChange,
|
|
19196
|
+
onEmptyChange: onEmptyChange,
|
|
19197
|
+
renderOption: ({
|
|
19198
|
+
label,
|
|
19199
|
+
input
|
|
19200
|
+
}) => highlightInputMatch(label, input),
|
|
19201
|
+
children: items.map(({
|
|
19202
|
+
label,
|
|
19203
|
+
value
|
|
19204
|
+
}) => (0,jsx_runtime_namespaceObject.jsx)(TypeaheadOption_TypeaheadOption, {
|
|
19205
|
+
value: value,
|
|
19206
|
+
label: label || value,
|
|
19207
|
+
isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
|
|
19208
|
+
children: label || value
|
|
19209
|
+
}, value))
|
|
19210
|
+
})
|
|
19235
19211
|
});
|
|
19236
19212
|
};
|
|
19237
19213
|
;// ./src/components/JsonSchemaForm/widgets/PasswordWidget.tsx
|