{"version":3,"file":"PasswordField.cjs","names":["_react","require","_Field","_i18n","_index","_inputUtils","_jsxRuntime","_interopRequireDefault","e","__esModule","default","PasswordField","forwardRef","ariaDescribedBy","autoCompleteType","defaultValue","errorMessage","errorMessageList","hasInitialFocus","hint","id","idOverride","inputRef","isDisabled","isFullWidth","isOptional","hasShowPassword","isReadOnly","label","name","nameOverride","onChange","onChangeProp","onFocus","onBlur","placeholder","showPasswordToggleAriaLabel","testId","translate","value","ref","t","useTranslation","inputType","setInputType","useState","togglePasswordVisibility","useCallback","controlledStateRef","useRef","getControlState","controlledValue","uncontrolledValue","inputValues","useInputValues","controlState","current","localInputRef","useImperativeHandle","focus","event","renderFieldComponent","errorMessageElementId","labelElementId","jsx","_InputBase2","autoComplete","autoFocus","endAdornment","_InputAdornment2","position","children","_IconButton2","onClick","ShowIcon","HideIcon","inputProps","role","readOnly","required","type","Field","fieldType","hasVisibleLabel","MemoizedPasswordField","exports","memo","displayName"],"sources":["../../src/PasswordField.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 { IconButton, InputAdornment, InputBase } from \"@mui/material\";\nimport {\n  ChangeEventHandler,\n  FocusEventHandler,\n  forwardRef,\n  memo,\n  useCallback,\n  useImperativeHandle,\n  useRef,\n  useState,\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 { useTranslation } from \"./i18n.generated/i18n.js\";\nimport { HideIcon, ShowIcon } from \"./icons.generated/index.js\";\nimport { FocusHandle, getControlState, useInputValues } from \"./inputUtils.js\";\n\nexport type PasswordFieldProps = {\n  /**\n   * Controls the browser autocomplete hint for the password field.\n   * - If `'current-password'`, hints that the field is for signing in with an existing password.\n   * - If `'new-password'`, hints that the field is for creating or updating a password; browsers may suggest a strong password.\n   */\n  autoCompleteType?: \"current-password\" | \"new-password\";\n  /**\n   * initial value for input. Use when component in uncontrolled.\n   */\n  defaultValue?: string;\n  /**\n   * If `true`, the input receives focus automatically on mount.\n   */\n  hasInitialFocus?: boolean;\n  /**\n   * If `true`, renders a toggle button that lets the user reveal or hide the password value.\n   * @default true\n   */\n  hasShowPassword?: boolean;\n  /**\n   * Ref attached to the underlying <input> element.\n   */\n  inputRef?: React.RefObject<FocusHandle>;\n  /**\n   * The label for the `input` element.\n   */\n  label: string;\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   * Accessible name for the password visibility toggle. This is a stable name that does not change when the password is shown or hidden — the toggle's pressed state is conveyed through `aria-pressed`, so the name must stay constant to follow the ARIA toggle-button pattern. Override per instance when a page has more than one PasswordField (or when collecting other sensitive input such as a security answer) so screen-reader users can tell the toggles apart (e.g. \"Show re-entered password\").\n   */\n  showPasswordToggleAriaLabel?: string;\n  /**\n   * The value of the `input` element. Use when component is controlled.\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 text field for collecting sensitive input such as passwords. Renders a masked input with an optional toggle button that lets users reveal or hide the entered value.\n */\nconst PasswordField = forwardRef<HTMLInputElement, PasswordFieldProps>(\n  (\n    {\n      ariaDescribedBy,\n      autoCompleteType,\n      defaultValue,\n      errorMessage,\n      errorMessageList,\n      hasInitialFocus,\n      hint,\n      id: idOverride,\n      inputRef,\n      isDisabled = false,\n      isFullWidth = false,\n      isOptional = false,\n      hasShowPassword = true,\n      isReadOnly,\n      label,\n      name: nameOverride,\n      onChange: onChangeProp,\n      onFocus,\n      onBlur,\n      placeholder,\n      showPasswordToggleAriaLabel,\n      testId,\n      translate,\n      value,\n    },\n    ref,\n  ) => {\n    const { t } = useTranslation();\n    const [inputType, setInputType] = useState(\"password\");\n\n    const togglePasswordVisibility = useCallback(() => {\n      setInputType((inputType) =>\n        inputType === \"password\" ? \"text\" : \"password\",\n      );\n    }, []);\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      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={inputType === \"password\" ? autoCompleteType : \"off\"}\n          /* eslint-disable-next-line jsx-a11y/no-autofocus */\n          autoFocus={hasInitialFocus}\n          endAdornment={\n            hasShowPassword && (\n              <InputAdornment position=\"end\">\n                <IconButton\n                  aria-controls={id}\n                  aria-label={\n                    showPasswordToggleAriaLabel ??\n                    t(\"passwordfield.icon.label.show\")\n                  }\n                  aria-pressed={inputType === \"text\"}\n                  onClick={togglePasswordVisibility}\n                >\n                  {inputType === \"password\" ? <ShowIcon /> : <HideIcon />}\n                </IconButton>\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            // role: \"textbox\" Added because password inputs don't have an implicit role assigned. This causes problems with element selection.\n            role: \"textbox\",\n          }}\n          inputRef={localInputRef}\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          translate={translate}\n          type={inputType}\n        />\n      ),\n      [\n        autoCompleteType,\n        hasInitialFocus,\n        inputValues,\n        t,\n        togglePasswordVisibility,\n        inputType,\n        nameOverride,\n        onChange,\n        onFocus,\n        onBlur,\n        placeholder,\n        isOptional,\n        isReadOnly,\n        hasShowPassword,\n        ref,\n        showPasswordToggleAriaLabel,\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        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 MemoizedPasswordField = memo(PasswordField);\nMemoizedPasswordField.displayName = \"PasswordField\";\n\nexport { MemoizedPasswordField as PasswordField };\n"],"mappings":";;;;;;;;;AAaA,IAAAA,MAAA,GAAAC,OAAA;AAaA,IAAAC,MAAA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