{"version":3,"file":"NativeSelect.cjs","names":["_react","_interopRequireWildcard","require","_Field","_inputUtils","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_interopRequireDefault","NativeSelect","forwardRef","ariaDescribedBy","autoCompleteType","defaultValue","errorMessage","errorMessageList","hasMultipleChoices","hasMultipleChoicesProp","hint","HintLinkComponent","id","idOverride","inputRef","isDisabled","isFullWidth","isMultiSelect","isOptional","label","onBlur","onChange","onChangeProp","onFocus","testId","translate","value","children","ref","controlledStateRef","useRef","getControlState","controlledValue","uncontrolledValue","localInputRef","useImperativeHandle","focus","current","inputValues","useInputValues","controlState","useCallback","event","child","useMemo","undefined","renderFieldComponent","errorMessageElementId","labelElementId","jsx","_Select2","autoComplete","inputProps","multiple","name","native","Field","fieldType","hasVisibleLabel","MemoizedNativeSelect","exports","memo","displayName"],"sources":["../../src/NativeSelect.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n  Select as MuiSelect,\n  SelectProps as MuiSelectProps,\n} from \"@mui/material\";\nimport React, {\n  forwardRef,\n  InputHTMLAttributes,\n  memo,\n  ReactElement,\n  useCallback,\n  useImperativeHandle,\n  useMemo,\n  useRef,\n} from \"react\";\n\nimport type { HtmlProps } from \"./HtmlProps.js\";\n\nimport { Field } from \"./Field.js\";\nimport {\n  FieldComponentProps,\n  FieldComponentRenderProps,\n} from \"./FieldComponentProps.js\";\nimport { FocusHandle, getControlState, useInputValues } from \"./inputUtils.js\";\n\nexport type NativeSelectOption = {\n  text: string;\n  type?: \"heading\" | \"option\";\n  value?: string;\n};\n\nexport type NativeSelectValueType<HasMultipleChoices> =\n  HasMultipleChoices extends true ? string[] : string;\n\nexport type NativeSelectProps<\n  Value extends NativeSelectValueType<HasMultipleChoices>,\n  HasMultipleChoices extends boolean,\n> = {\n  /**\n   * This prop helps users to fill forms faster, especially on mobile devices. The name can be confusing, as it's more like an autofill.\n   * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill\n   */\n  autoCompleteType?: InputHTMLAttributes<HTMLInputElement>[\"autoComplete\"];\n  /**\n   * The options or optgroup elements within the NativeSelect\n   */\n  children?: ReactElement<\"option\"> | ReactElement<\"optgroup\">;\n  /**\n   * The default value of the NativeSelect. Use when component is uncontrolled\n   */\n  defaultValue?: Value;\n  /**\n   * If `true`, the select allows multiple options to be selected simultaneously.\n   */\n  hasMultipleChoices?: HasMultipleChoices;\n  /**\n   * Ref attached to the underlying <select> element.\n   */\n  inputRef?: React.RefObject<FocusHandle>;\n  /**\n   * @deprecated Use `hasMultipleChoices` instead.\n   */\n  isMultiSelect?: HasMultipleChoices;\n  /**\n   * The label text for the NativeSelect\n   */\n  label: string;\n  /**\n   * Called when the NativeSelect loses focus.\n   */\n  onBlur?: MuiSelectProps<Value>[\"onBlur\"];\n  /**\n   * Called when the selected value of the NativeSelect changes.\n   */\n  onChange?: MuiSelectProps<Value>[\"onChange\"];\n  /**\n   * Called when the NativeSelect gains focus.\n   */\n  onFocus?: MuiSelectProps<Value>[\"onFocus\"];\n  /**\n   * @deprecated Pass `<option>` elements as `children` instead. This prop has no effect.\n   */\n  options?: Value;\n  /**\n   * The value or values selected in the NativeSelect. Use when component is controlled\n   */\n  value?: Value;\n} & Pick<\n  FieldComponentProps,\n  | \"errorMessage\"\n  | \"errorMessageList\"\n  | \"hint\"\n  | \"HintLinkComponent\"\n  | \"id\"\n  | \"isDisabled\"\n  | \"isFullWidth\"\n  | \"isOptional\"\n> &\n  Pick<HtmlProps, \"ariaDescribedBy\" | \"testId\" | \"translate\">;\n\ntype NativeSelectRenderProps = Partial<\n  Pick<FieldComponentRenderProps, \"ariaDescribedBy\" | \"errorMessageElementId\">\n> &\n  Pick<FieldComponentRenderProps, \"labelElementId\">;\n\n/**\n * A native HTML `<select>` element wrapped in an Odyssey field. Use when a lightweight, OS-rendered dropdown is preferred over the custom Select component.\n */\nconst NativeSelect = forwardRef(\n  <\n    Value extends NativeSelectValueType<HasMultipleChoices>,\n    HasMultipleChoices extends boolean,\n  >(\n    {\n      ariaDescribedBy,\n      autoCompleteType,\n      defaultValue,\n      errorMessage,\n      errorMessageList,\n      hasMultipleChoices: hasMultipleChoicesProp,\n      hint,\n      HintLinkComponent,\n      id: idOverride,\n      inputRef,\n      isDisabled = false,\n      isFullWidth = false,\n      isMultiSelect,\n      isOptional = false,\n      label,\n      onBlur,\n      onChange: onChangeProp,\n      onFocus,\n      testId,\n      translate,\n      value,\n      children,\n    }: NativeSelectProps<Value, HasMultipleChoices>,\n    ref?: React.Ref<ReactElement>,\n  ) => {\n    const controlledStateRef = useRef(\n      getControlState({\n        controlledValue: value,\n        uncontrolledValue: defaultValue,\n      }),\n    );\n    const localInputRef = useRef<HTMLSelectElement>(null);\n\n    useImperativeHandle(inputRef, () => {\n      return {\n        focus: () => {\n          localInputRef.current?.focus();\n        },\n      };\n    }, []);\n\n    const inputValues = useInputValues({\n      defaultValue,\n      value,\n      controlState: controlledStateRef.current,\n    });\n\n    const onChange = useCallback<\n      NonNullable<MuiSelectProps<Value>[\"onChange\"]>\n    >(\n      (event, child) => {\n        onChangeProp?.(event, child);\n      },\n      [onChangeProp],\n    );\n\n    const hasMultipleChoices = useMemo(\n      () =>\n        hasMultipleChoicesProp === undefined\n          ? isMultiSelect\n          : hasMultipleChoicesProp,\n      [hasMultipleChoicesProp, isMultiSelect],\n    );\n    const renderFieldComponent = useCallback(\n      ({\n        ariaDescribedBy,\n        errorMessageElementId,\n        labelElementId,\n      }: NativeSelectRenderProps) => (\n        <MuiSelect\n          {...inputValues}\n          aria-describedby={ariaDescribedBy}\n          autoComplete={autoCompleteType}\n          children={children}\n          id={idOverride}\n          inputProps={{\n            \"aria-errormessage\": errorMessageElementId,\n            \"aria-labelledby\": labelElementId,\n            \"data-se\": testId,\n          }}\n          inputRef={localInputRef}\n          multiple={hasMultipleChoices}\n          name={idOverride}\n          native={true}\n          onBlur={onBlur}\n          onChange={onChange}\n          onFocus={onFocus}\n          ref={ref}\n          translate={translate}\n        />\n      ),\n      [\n        autoCompleteType,\n        children,\n        idOverride,\n        inputValues,\n        hasMultipleChoices,\n        onBlur,\n        onChange,\n        onFocus,\n        ref,\n        testId,\n        translate,\n      ],\n    );\n\n    return (\n      <Field\n        ariaDescribedBy={ariaDescribedBy}\n        errorMessage={errorMessage}\n        errorMessageList={errorMessageList}\n        fieldType=\"single\"\n        hasVisibleLabel\n        hint={hint}\n        HintLinkComponent={HintLinkComponent}\n        id={idOverride}\n        isDisabled={isDisabled}\n        isFullWidth={isFullWidth}\n        isOptional={isOptional}\n        label={label}\n        renderFieldComponent={renderFieldComponent}\n      />\n    );\n  },\n);\n\nconst MemoizedNativeSelect = memo(NativeSelect);\nMemoizedNativeSelect.displayName = \"NativeSelect\";\n\nexport { MemoizedNativeSelect as NativeSelect };\n"],"mappings":";;;;;;;AAgBA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAaA,IAAAC,MAAA,GAAAD,OAAA;AAKA,IAAAE,WAAA,GAAAF,OAAA;AAA+E,IAAAG,WAAA,GAAAH,OAAA;AAAA,SAAAD,wBAAAK,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAP,uBAAA,YAAAA,CAAAK,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EA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