Skip to content

Commit

Permalink
Fix #5135: Password expose toggleMask() method (#5136)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Oct 21, 2023
1 parent 5ba6169 commit 7e172dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions components/lib/password/Password.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const Password = React.memo(
}
};

const onMaskToggle = () => {
const toggleMask = () => {
setUnmaskedState((prevUnmasked) => !prevUnmasked);
};

Expand Down Expand Up @@ -229,6 +229,7 @@ export const Password = React.memo(

React.useImperativeHandle(ref, () => ({
props,
toggleMask,
focus: () => DomHandler.focus(inputRef.current),
getElement: () => elementRef.current,
getOverlay: () => overlayRef.current,
Expand Down Expand Up @@ -272,11 +273,11 @@ export const Password = React.memo(
const eyeIcon = IconUtils.getJSXIcon(icon, unmaskedState ? { ...hideIconProps } : { ...showIconProps }, { props });

if (props.toggleMask) {
let content = <i onClick={onMaskToggle}> {eyeIcon} </i>;
let content = <i onClick={toggleMask}> {eyeIcon} </i>;

if (props.icon) {
const defaultIconOptions = {
onClick: onMaskToggle,
onClick: toggleMask,
className,
element: content,
props
Expand Down
4 changes: 4 additions & 0 deletions components/lib/password/password.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ export declare class Password extends React.Component<PasswordProps, any> {
* Used to focus the component.
*/
public focus(): void;
/**
* Toggle the mask on or off.
*/
public toggleMask(): void;
/**
* Used to get container element.
* @return {HTMLDivElement} Container element
Expand Down

0 comments on commit 7e172dc

Please sign in to comment.