@codecademy/gamut
71.0.071.0.1-alpha.69ab4c.0
dist/Form/SelectDropdown/utils.js~
dist/Form/SelectDropdown/utils.jsModified+14
Index: package/dist/Form/SelectDropdown/utils.js
===================================================================
--- package/dist/Form/SelectDropdown/utils.js
+++ package/dist/Form/SelectDropdown/utils.js
@@ -1,6 +1,20 @@
export const isMultipleSelectProps = props => !!props.multiple;
export const isSingleSelectProps = props => !props.multiple;
+/**
+ * Resolves the value for a newly created option from react-select action metadata
+ * or the onChange option payload. Returns undefined when no reliable value exists.
+ */
+export const getCreatedOptionValue = (optionEvent, actionMeta, multiple) => {
+ const metaValue = actionMeta.option?.value;
+ if (metaValue) return metaValue;
+ if (!multiple) {
+ const value = optionEvent.value;
+ return value || undefined;
+ }
+ const newOption = optionEvent.find(option => option.__isNew__);
+ return newOption?.value || undefined;
+};
export const isOptionGroup = obj => obj != null && typeof obj === 'object' && 'options' in obj && obj.options !== undefined;
export const isOptionsGrouped = options => Array.isArray(options) && options.some(option => isOptionGroup(option));
/**