From 369443250aad2fe7853f1d992ec8c876553a2071 Mon Sep 17 00:00:00 2001 From: melloware Date: Sat, 21 Oct 2023 10:42:56 -0400 Subject: [PATCH] Fix #5135: Password expose toggleMask() method --- components/lib/password/Password.js | 7 ++++--- components/lib/password/password.d.ts | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/lib/password/Password.js b/components/lib/password/Password.js index 4a292455b6..8926c549c0 100644 --- a/components/lib/password/Password.js +++ b/components/lib/password/Password.js @@ -98,7 +98,7 @@ export const Password = React.memo( } }; - const onMaskToggle = () => { + const toggleMask = () => { setUnmaskedState((prevUnmasked) => !prevUnmasked); }; @@ -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, @@ -272,11 +273,11 @@ 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: onMaskToggle, + onClick: toggleMask, className, element: content, props diff --git a/components/lib/password/password.d.ts b/components/lib/password/password.d.ts index e1a09c9296..8a221c443b 100644 --- a/components/lib/password/password.d.ts +++ b/components/lib/password/password.d.ts @@ -308,6 +308,10 @@ export declare class Password extends React.Component { * 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