Skip to content

Commit

Permalink
chore: Use visibilityToggle prop to control password input visibility (
Browse files Browse the repository at this point in the history
  • Loading branch information
lyndsiWilliams authored Jan 4, 2023
1 parent ebaad10 commit cf156f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('LabeledErrorBoundInput', () => {
expect(textboxInput).toBeVisible();
expect(errorText).toBeVisible();
});

it('renders a LabeledErrorBoundInput with a InfoTooltip', async () => {
defaultProps.hasTooltip = true;
render(<LabeledErrorBoundInput {...defaultProps} />);
Expand All @@ -75,4 +76,18 @@ describe('LabeledErrorBoundInput', () => {
expect(textboxInput).toBeVisible();
expect(await screen.findByText('This is a tooltip')).toBeInTheDocument();
});

it('becomes a password input if visibilityToggle prop is passed in', async () => {
defaultProps.visibilityToggle = true;
render(<LabeledErrorBoundInput {...defaultProps} />);

expect(await screen.findByRole('img', { name: /eye/i })).toBeVisible();
});

it('becomes a password input if props.name === password (backwards compatibility)', async () => {
defaultProps.name = 'password';
render(<LabeledErrorBoundInput {...defaultProps} />);

expect(await screen.findByRole('img', { name: /eye/i })).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface LabeledErrorBoundInputProps {
tooltipText?: string | null;
id?: string;
classname?: string;
visibilityToggle?: boolean;
[x: string]: any;
}

Expand Down Expand Up @@ -101,6 +102,7 @@ const LabeledErrorBoundInput = ({
tooltipText,
id,
className,
visibilityToggle,
...props
}: LabeledErrorBoundInputProps) => (
<StyledFormGroup className={className}>
Expand All @@ -119,7 +121,7 @@ const LabeledErrorBoundInput = ({
help={errorMessage || helpText}
hasFeedback={!!errorMessage}
>
{props.name === 'password' ? (
{visibilityToggle || props.name === 'password' ? (
<StyledInputPassword
{...props}
{...validationMethods}
Expand Down

0 comments on commit cf156f1

Please sign in to comment.