Skip to content

Commit

Permalink
Fix primefaces#6396: Password use IconField for toggle mask
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Apr 29, 2024
1 parent b3d109a commit 8e18f68
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions components/lib/password/Password.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -297,6 +299,10 @@ export const Password = React.memo(
};

const createIcon = () => {
if (!props.toggleMask) {
return null;
}

let icon;

const hideIconProps = mergeProps(
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -476,10 +478,20 @@ export const Password = React.memo(
ptm('input')
);

let input = <InputText {...inputTextProps} />;

if (icon) {
input = (
<IconField>
<InputIcon>{icon}</InputIcon>
{input}
</IconField>
);
}

return (
<div {...rootProps}>
<InputText {...inputTextProps} />
{icon}
{input}
{panel}
</div>
);
Expand Down

0 comments on commit 8e18f68

Please sign in to comment.