aport-tools 4.4.20 → 4.4.22
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.esm.js +18 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
1
|
+
/*! aport-tools v4.4.22 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
@@ -778,61 +778,61 @@ var InputList = function InputList(_a) {
|
|
778
778
|
selectedOptions = _l[0],
|
779
779
|
setSelectedOptions = _l[1];
|
780
780
|
// Update form value on mount if firstValue is provided
|
781
|
-
// Update form value and internal state on mount or `firstValue` change
|
782
781
|
React.useEffect(function () {
|
783
782
|
if (firstValue && selectedOptions !== firstValue) {
|
784
|
-
setSelectedOptions(
|
785
|
-
setFormValue(name, multi ? initialSelections : initialSelections[0] || null);
|
783
|
+
setSelectedOptions(firstValue); // Only update if necessary
|
786
784
|
}
|
787
|
-
}, [firstValue,
|
788
|
-
// Handle option selection
|
785
|
+
}, [firstValue, selectedOptions]);
|
789
786
|
var handleSelectOption = function handleSelectOption(option) {
|
790
787
|
var updatedSelections;
|
791
788
|
if (multi) {
|
792
|
-
|
789
|
+
// Ensure selectedOptions is treated as an array
|
790
|
+
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
791
|
+
var alreadySelected = selectedArray.some(function (opt) {
|
793
792
|
return opt.id === option.id;
|
794
793
|
});
|
795
|
-
updatedSelections = alreadySelected ?
|
794
|
+
updatedSelections = alreadySelected ? selectedArray.filter(function (opt) {
|
796
795
|
return opt.id !== option.id;
|
797
|
-
}) :
|
796
|
+
}) : __spreadArray(__spreadArray([], selectedArray, true), [option], false);
|
798
797
|
if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
|
799
798
|
setIsDropdownVisible(false);
|
800
799
|
}
|
800
|
+
setFormValue(name, updatedSelections);
|
801
801
|
} else {
|
802
|
+
// Handle single-selection case
|
802
803
|
updatedSelections = option;
|
804
|
+
setFormValue(name, option);
|
803
805
|
if (closeOnSelect) setIsDropdownVisible(false);
|
804
806
|
}
|
805
|
-
|
806
|
-
setFormValue(name, updatedSelections);
|
807
|
+
// Trigger onChange callback with the updated selection
|
807
808
|
if (onChange) {
|
808
809
|
onChange(updatedSelections);
|
809
810
|
}
|
810
811
|
};
|
811
|
-
// Check if an option should be disabled
|
812
812
|
var isItemDisabled = function isItemDisabled(option) {
|
813
|
-
if (!multi) return false;
|
814
|
-
|
813
|
+
if (!multi) return false; // Disable check only applies for multi-select
|
814
|
+
// Ensure selectedOptions is treated as an array
|
815
|
+
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
816
|
+
return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
|
815
817
|
return opt.id === option.id;
|
816
818
|
});
|
817
819
|
};
|
818
|
-
// Render selected text
|
819
820
|
var renderSelectedText = function renderSelectedText() {
|
820
821
|
if (multi) {
|
822
|
+
// Ensure selectedOptions is treated as an array
|
821
823
|
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
822
824
|
return selectedArray.map(function (opt) {
|
823
825
|
return opt.label;
|
824
|
-
}).join(
|
826
|
+
}).join(', ') || placeholder;
|
825
827
|
}
|
826
828
|
return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
|
827
829
|
};
|
828
|
-
// Toggle dropdown visibility
|
829
830
|
var toggleDropdown = function toggleDropdown() {
|
830
831
|
if (!disabled) {
|
831
832
|
setIsDropdownVisible(!isDropdownVisible);
|
832
833
|
if (!isDropdownVisible) reactNative.Keyboard.dismiss();
|
833
834
|
}
|
834
835
|
};
|
835
|
-
// Close dropdown
|
836
836
|
var handleCloseDropdown = React.useCallback(function () {
|
837
837
|
if (isDropdownVisible) setIsDropdownVisible(false);
|
838
838
|
}, [isDropdownVisible]);
|