Skip to content

Commit

Permalink
Added option to disable password reveal functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Perez <[email protected]>
  • Loading branch information
Benjamin Perez committed Nov 8, 2024
1 parent a0ae0dc commit 2bfbc77
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/components/InputBox/InputBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ PasswordInput.args = {
type: "password",
};

export const PasswordInputRevealDisabled = Template.bind({});
PasswordInputRevealDisabled.args = {
label: "An input box",
required: true,
tooltip: "Tooltip text",
type: "password",
passwordRevealEnabled: false,
};

export const WithOverlayIcon = Template.bind({});
WithOverlayIcon.args = {
label: "An input box",
Expand Down
3 changes: 3 additions & 0 deletions src/components/InputBox/InputBox.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export const containerSizeSmall = css({
});

export const containerOverlayIcon = css({
"& input": {
paddingRight: 37,
},
"& .accessoryIcon": {
right: 37,
},
Expand Down
1 change: 1 addition & 0 deletions src/components/InputBox/InputBox.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ export interface InputBoxProps
sizeMode?: InputBoxSize;
orientation?: InputBoxOrientation;
disableErrorUntilFocus?: boolean;
passwordRevealEnabled?: boolean;
}
7 changes: 5 additions & 2 deletions src/components/InputBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Inputdiv = React.forwardRef<
onFocus,
disableErrorUntilFocus = false,
children,
passwordRevealEnabled = true,
value,
...props
},
Expand All @@ -86,7 +87,7 @@ const Inputdiv = React.forwardRef<
let inputdivWrapperIcon = overlayIcon;
let inputdivWrapperType = type;

if (type === "password" && !overlayIcon) {
if (type === "password" && passwordRevealEnabled && !overlayIcon) {
inputdivWrapperIcon = toggleTextInput ? <EyeOffIcon /> : <EyeIcon />;
inputdivWrapperType = toggleTextInput ? "text" : "password";
}
Expand All @@ -110,7 +111,9 @@ const Inputdiv = React.forwardRef<
css={[
containerStyles,
sizeMode === "small" ? containerSizeSmall : {},
overlayIcon || type === "password" ? containerOverlayIcon : {},
overlayIcon || (type === "password" && passwordRevealEnabled)
? containerOverlayIcon
: {},
css({ flexDirection: orientation === "vertical" ? "column" : "row" }),
overrideThemes,
]}
Expand Down

0 comments on commit 2bfbc77

Please sign in to comment.