Skip to content

Commit d11731c

Browse files
author
Hector Arce De Las Heras
committed
Update onIconClick prop in components
This commit fixes the onIconClick prop so it now works as expected. However, it's important to note that this prop will be deprecated in the next major release. Instead, users should transition to using activeIcon onClick and disabledIcon onClick for handling icon click events. This change is part of our ongoing efforts to improve the API and usability of our components.
1 parent 05a2ed3 commit d11731c

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/components/inputPassword/inputPassword.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,20 @@ const InputPasswordComponent = React.forwardRef(
4848
ctv
4949
);
5050

51-
const icon = inputPasswordType === InputTypeType.PASSWORD ? disabledIcon : activeIcon;
52-
53-
const setTypeInput: React.MouseEventHandler<HTMLButtonElement> = event => {
51+
const handleRightIconClick: React.MouseEventHandler<HTMLButtonElement> = event => {
5452
const icon = inputPasswordType === InputTypeType.PASSWORD ? disabledIcon : activeIcon;
5553

5654
setInputPasswordType(
5755
inputPasswordType === InputTypeType.PASSWORD ? InputTypeType.TEXT : InputTypeType.PASSWORD
5856
);
5957
onInputTypeChange && onInputTypeChange();
6058
// deprecated - Remove this icon.onClick when the 'icon' is removed from the component
61-
icon.onClick?.(
59+
const iconClickValue =
6260
inputPasswordType === InputTypeType.PASSWORD
6361
? OnIconClickValueType.VISIBLE
64-
: OnIconClickValueType.HIDE,
65-
event
66-
);
62+
: OnIconClickValueType.HIDE;
63+
icon.onClick?.(iconClickValue, event);
64+
onIconClick?.(iconClickValue);
6765
};
6866

6967
const {
@@ -94,14 +92,16 @@ const InputPasswordComponent = React.forwardRef(
9492
onInternalErrors,
9593
});
9694

95+
const icon = inputPasswordType === InputTypeType.PASSWORD ? disabledIcon : activeIcon;
96+
9797
return (
9898
<InputPasswordStandAlone
9999
{...props}
100100
ref={inputRef}
101101
maxLength={maxLength}
102102
rightIcon={{
103103
...icon,
104-
onClick: event => setTypeInput(event),
104+
onClick: handleRightIconClick,
105105
}}
106106
state={state}
107107
styles={styles}

src/components/inputPassword/stories/inputPassword.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const commonArgs: IInputPassword = {
4040
placeholder: 'Placeholder',
4141
required: true,
4242
helpMessage: { content: 'HEEEELP!' },
43-
activeIcon: { icon: ICONS.ICON_GHOST, altText: 'Show password' },
44-
disabledIcon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'Hide password' },
43+
activeIcon: { icon: ICONS.ICON_GHOST, altText: 'Hide password' },
44+
disabledIcon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'Show password' },
4545
errorMessage: { content: 'Error message' },
4646
errorIcon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'error' },
4747
secondaryLabel: labelSecondary(themeSelected),

src/components/inputPassword/types/inputPassword.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,8 @@ export interface IInputPassword<V = undefined extends string ? unknown : string>
4545
onInputTypeChange?: () => void;
4646
onInternalErrors?: (errors: string[]) => void;
4747
onError?: (error: boolean) => void;
48+
/**
49+
* @deprecated This prop will be deprecated in the next major. Use instead activeIcon onClick and disabledIcon on click
50+
*/
4851
onIconClick?: (value: OnIconClickValueType) => void;
4952
}

0 commit comments

Comments
 (0)