@codecademy/gamut

72.0.272.0.3-alpha.8100dc.0
dist/Form/SelectDropdown/utils.js
~dist/Form/SelectDropdown/utils.jsModified
+16
Index: package/dist/Form/SelectDropdown/utils.js
===================================================================
--- package/dist/Form/SelectDropdown/utils.js
+++ package/dist/Form/SelectDropdown/utils.js
@@ -1,6 +1,22 @@
 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;
+    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));
 
 /**