From 8e18f68e2e8074c27cbcfe73d3f3cab99a3ebddd Mon Sep 17 00:00:00 2001 From: melloware Date: Mon, 29 Apr 2024 13:19:56 -0400 Subject: [PATCH] Fix #6396: Password use IconField for toggle mask --- components/lib/password/Password.js | 44 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/components/lib/password/Password.js b/components/lib/password/Password.js index d85f7b60d7..e26ab8fcf4 100644 --- a/components/lib/password/Password.js +++ b/components/lib/password/Password.js @@ -3,8 +3,10 @@ import PrimeReact, { PrimeReactContext, ariaLabel, localeOption } from '../api/A import { useHandleStyle } from '../componentbase/ComponentBase'; import { CSSTransition } from '../csstransition/CSSTransition'; import { ESC_KEY_HANDLING_PRIORITIES, useDisplayOrder, useGlobalOnEscapeKey, useMergeProps, useMountEffect, useOverlayListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks'; +import { IconField } from '../iconfield/IconField'; import { EyeIcon } from '../icons/eye'; import { EyeSlashIcon } from '../icons/eyeslash'; +import { InputIcon } from '../inputicon/InputIcon'; import { InputText } from '../inputtext/InputText'; import { OverlayService } from '../overlayservice/OverlayService'; import { Portal } from '../portal/Portal'; @@ -297,6 +299,10 @@ export const Password = React.memo( }; const createIcon = () => { + if (!props.toggleMask) { + return null; + } + let icon; const hideIconProps = mergeProps( @@ -335,24 +341,20 @@ export const Password = React.memo( const eyeIcon = IconUtils.getJSXIcon(icon, unmaskedState ? { ...hideIconProps } : { ...showIconProps }, { props }); - if (props.toggleMask) { - let content = eyeIcon; + let content = eyeIcon; - if (props.icon) { - const defaultIconOptions = { - onClick: toggleMask, - className, - element: content, - props - }; - - content = ObjectUtils.getJSXElement(props.icon, defaultIconOptions); - } + if (props.icon) { + const defaultIconOptions = { + onClick: toggleMask, + className, + element: content, + props + }; - return content; + content = ObjectUtils.getJSXElement(props.icon, defaultIconOptions); } - return null; + return content; }; const createPanel = () => { @@ -476,10 +478,20 @@ export const Password = React.memo( ptm('input') ); + let input = ; + + if (icon) { + input = ( + + {icon} + {input} + + ); + } + return (
- - {icon} + {input} {panel}
);