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