{"version":3,"file":"TextField.cjs","names":["_react","require","_Field","_inputUtils","_jsxRuntime","_interopRequireDefault","e","__esModule","default","textFieldTypeValues","exports","TextField","forwardRef","ariaDescribedBy","autoCompleteType","defaultValue","hasInitialFocus","endAdornment","errorMessage","errorMessageList","hint","HintLinkComponent","id","idOverride","inputRef","inputMode","isDisabled","isFullWidth","isMultiline","isOptional","isReadOnly","label","max","min","name","nameOverride","onBlur","onChange","onChangeProp","onFocus","placeholder","startAdornment","step","testId","translate","type","value","ref","controlledStateRef","useRef","getControlState","controlledValue","uncontrolledValue","inputValues","useInputValues","controlState","current","localInputRef","useImperativeHandle","focus","useCallback","event","renderFieldComponent","errorMessageElementId","labelElementId","jsx","_InputBase2","autoComplete","autoFocus","_InputAdornment2","position","children","inputProps","multiline","readOnly","required","Field","fieldType","hasVisibleLabel","MemoizedTextField","memo","displayName"],"sources":["../../src/TextField.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 { InputAdornment, InputBase } from \"@mui/material\";\nimport {\n  ChangeEventHandler,\n  FocusEventHandler,\n  forwardRef,\n  InputHTMLAttributes,\n  memo,\n  ReactElement,\n  useCallback,\n  useImperativeHandle,\n  useRef,\n} from \"react\";\n\nimport { Field } from \"./Field.js\";\nimport {\n  FieldComponentProps,\n  FieldComponentRenderProps,\n} from \"./FieldComponentProps.js\";\nimport { HtmlProps } from \"./HtmlProps.js\";\nimport { FocusHandle, getControlState, useInputValues } from \"./inputUtils.js\";\n\nexport const textFieldTypeValues = [\n  \"email\",\n  \"number\",\n  \"tel\",\n  \"text\",\n  \"url\",\n] as const;\n\nexport type TextFieldProps = {\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 default value. Use when the component is not controlled.\n   */\n  defaultValue?: string;\n  /**\n   * End `InputAdornment` for this component.\n   */\n  endAdornment?: string | ReactElement;\n  /**\n   * If `true`, the input receives focus automatically on mount.\n   */\n  hasInitialFocus?: boolean;\n  /**\n   * Hints at the type of data that might be entered by the user while editing the element or its contents.\n   * @see https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute\n   */\n  inputMode?: InputHTMLAttributes<HTMLInputElement>[\"inputMode\"];\n  /**\n   * Ref attached to the underlying <input> element.\n   */\n  inputRef?: React.RefObject<FocusHandle>;\n  /**\n   * If `true`, the input renders as a multiline textarea.\n   */\n  isMultiline?: boolean;\n  /**\n   * The label for the `input` element.\n   */\n  label: string;\n  /**\n   * The maximum value for a `number` input.\n   */\n  max?: number;\n  /**\n   * The minimum value for a `number` input.\n   */\n  min?: number;\n  /**\n   * Called when the input loses focus.\n   */\n  onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;\n  /**\n   * Called when the input value changes.\n   */\n  onChange?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;\n  /**\n   * Called when the input gains focus.\n   */\n  onFocus?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;\n  /**\n   * The short hint displayed in the `input` before the user enters a value.\n   */\n  placeholder?: string;\n  /**\n   * Start `InputAdornment` for this component.\n   */\n  startAdornment?: string | ReactElement;\n  /**\n   * The step interval for a `number` input.\n   */\n  step?: number;\n  /**\n   * Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).\n   * @default \"text\"\n   */\n  type?: (typeof textFieldTypeValues)[number];\n  /**\n   * The value of the `input` element, required for a controlled component.\n   */\n  value?: string;\n} & FieldComponentProps &\n  Pick<HtmlProps, \"ariaDescribedBy\" | \"testId\" | \"translate\">;\n\ntype FieldRenderProps = Partial<\n  Pick<FieldComponentRenderProps, \"ariaDescribedBy\" | \"errorMessageElementId\">\n> &\n  Pick<FieldComponentRenderProps, \"id\" | \"labelElementId\">;\n\n/**\n * A single-line or multiline text input field with label, hint, and error support. Use for collecting free-form text input such as names, emails, URLs, or numbers.\n */\nconst TextField = forwardRef<HTMLInputElement, TextFieldProps>(\n  (\n    {\n      ariaDescribedBy,\n      autoCompleteType,\n      defaultValue,\n      hasInitialFocus,\n      endAdornment,\n      errorMessage,\n      errorMessageList,\n      hint,\n      HintLinkComponent,\n      id: idOverride,\n      inputRef,\n      inputMode,\n      isDisabled = false,\n      isFullWidth = false,\n      isMultiline = false,\n      isOptional = false,\n      isReadOnly,\n      label,\n      max,\n      min,\n      name: nameOverride,\n      onBlur,\n      onChange: onChangeProp,\n      onFocus,\n      placeholder,\n      startAdornment,\n      step,\n      testId,\n      translate,\n      type = \"text\",\n      value: value,\n    },\n    ref,\n  ) => {\n    const controlledStateRef = useRef(\n      getControlState({\n        controlledValue: value,\n        uncontrolledValue: defaultValue,\n      }),\n    );\n    const inputValues = useInputValues({\n      defaultValue,\n      value,\n      controlState: controlledStateRef.current,\n    });\n\n    const localInputRef = useRef<HTMLInputElement>(null);\n    useImperativeHandle(inputRef, () => {\n      return {\n        focus: () => {\n          localInputRef.current?.focus();\n        },\n      };\n    }, []);\n\n    const onChange = useCallback<\n      NonNullable<ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>>\n    >(\n      (event) => {\n        onChangeProp?.(event);\n      },\n      [onChangeProp],\n    );\n\n    const renderFieldComponent = useCallback(\n      ({\n        ariaDescribedBy,\n        errorMessageElementId,\n        id,\n        labelElementId,\n      }: FieldRenderProps) => (\n        <InputBase\n          {...inputValues}\n          aria-describedby={ariaDescribedBy}\n          autoComplete={autoCompleteType}\n          /* eslint-disable-next-line jsx-a11y/no-autofocus */\n          autoFocus={hasInitialFocus}\n          endAdornment={\n            endAdornment && (\n              <InputAdornment position=\"end\" translate={translate}>\n                {endAdornment}\n              </InputAdornment>\n            )\n          }\n          id={id}\n          inputProps={{\n            \"aria-errormessage\": errorMessageElementId,\n            \"aria-labelledby\": labelElementId,\n            \"aria-readonly\": isReadOnly,\n            \"data-se\": testId,\n            inputMode,\n            max,\n            min,\n            step,\n          }}\n          inputRef={localInputRef}\n          multiline={isMultiline}\n          name={nameOverride ?? id}\n          onBlur={onBlur}\n          onChange={onChange}\n          onFocus={onFocus}\n          placeholder={placeholder}\n          readOnly={isReadOnly}\n          ref={ref}\n          required={!isOptional}\n          startAdornment={\n            startAdornment && (\n              <InputAdornment position=\"start\" translate={translate}>\n                {startAdornment}\n              </InputAdornment>\n            )\n          }\n          translate={translate}\n          type={type}\n        />\n      ),\n      [\n        autoCompleteType,\n        inputValues,\n        hasInitialFocus,\n        endAdornment,\n        inputMode,\n        max,\n        min,\n        isMultiline,\n        nameOverride,\n        onBlur,\n        onChange,\n        onFocus,\n        placeholder,\n        isOptional,\n        isReadOnly,\n        ref,\n        startAdornment,\n        step,\n        testId,\n        translate,\n        type,\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        isReadOnly={isReadOnly}\n        label={label}\n        renderFieldComponent={renderFieldComponent}\n      />\n    );\n  },\n);\n\nconst MemoizedTextField = memo(TextField);\nMemoizedTextField.displayName = \"TextField\";\n\nexport { MemoizedTextField as TextField };\n"],"mappings":";;;;;;;;AAaA,IAAAA,MAAA,GAAAC,OAAA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