Skip to content

Commit

Permalink
wizard: create new component with add eyeIcon button inside textInput
Browse files Browse the repository at this point in the history
this commit create new component with add eyeIcon button inside textInput,
for password field
  • Loading branch information
mgold1234 committed Jan 23, 2025
1 parent 0f86336 commit 6d36b0a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
51 changes: 51 additions & 0 deletions src/Components/CreateImageWizard/ValidatedTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {
HelperTextItem,
TextInput,
TextInputProps,
Button,
InputGroup,
InputGroupItem,
} from '@patternfly/react-core';
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons';

import type { StepValidation } from './utilities/useValidation';

Expand All @@ -30,6 +34,53 @@ interface HookValidatedTextInputPropTypes extends TextInputProps {
warning?: string;
}

export const HookPasswordValidatedInput = ({
ariaLabel,
dataTestId,
value,
ouiaId,
stepValidation,
fieldName,
onChange,
warning = undefined,

Check failure on line 45 in src/Components/CreateImageWizard/ValidatedTextInput.tsx

View workflow job for this annotation

GitHub Actions / dev-check

'warning' is assigned a value but never used
...rest

Check failure on line 46 in src/Components/CreateImageWizard/ValidatedTextInput.tsx

View workflow job for this annotation

GitHub Actions / dev-check

Delete `··`
}: HookValidatedTextInputPropTypes) => {
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
const togglePasswordVisibility = () => {
setIsPasswordVisible(!isPasswordVisible);
};

return (
<>
<InputGroup>
<InputGroupItem isFill>
<HookValidatedInput
type={isPasswordVisible ? 'text' : 'password'}
ouiaId={ouiaId || ''}
data-testid={dataTestId}
value={value}
onChange={onChange!}
stepValidation={stepValidation}
ariaLabel={ariaLabel || ''}
fieldName={fieldName}
{...rest}

Check failure on line 66 in src/Components/CreateImageWizard/ValidatedTextInput.tsx

View workflow job for this annotation

GitHub Actions / dev-check

Delete `⏎`

/>
</InputGroupItem>
<InputGroupItem>
<Button
variant="control"
onClick={togglePasswordVisibility}
aria-label={isPasswordVisible ? 'Show password' : 'Hide password'}
>
{isPasswordVisible ? <EyeSlashIcon /> : <EyeIcon />}
</Button>
</InputGroupItem>
</InputGroup>
</>
);
};

export const HookValidatedInput = ({
dataTestId,
ouiaId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
setUserAdministratorByIndex,
} from '../../../../../store/wizardSlice';
import { useUsersValidation } from '../../../utilities/useValidation';
import { HookValidatedInput } from '../../../ValidatedTextInput';
import {
HookPasswordValidatedInput,
HookValidatedInput,
} from '../../../ValidatedTextInput';
const UserInfo = () => {
const dispatch = useAppDispatch();
const index = 0;
Expand Down Expand Up @@ -74,7 +77,7 @@ const UserInfo = () => {
/>
</FormGroup>
<FormGroup isRequired label="Password">
<HookValidatedInput
<HookPasswordValidatedInput
ariaLabel="blueprint user password"
value={userPassword || ''}
onChange={(_e, value) => handlePasswordChange(_e, value)}
Expand Down

0 comments on commit 6d36b0a

Please sign in to comment.