Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/react-core/src/components/LoginPage/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface LoginFormProps extends Omit<React.HTMLProps<HTMLFormElement>, '
usernameLabel?: string;
/** Value for the username */
usernameValue?: string;
/** Autocomplete value for the username input field */
usernameAutoComplete?: string;
/** Function that handles the onChange event for the username */
onChangeUsername?: (event: React.FormEvent<HTMLInputElement>, value: string) => void;
/** Flag indicating if the username is valid */
Expand All @@ -34,6 +36,8 @@ export interface LoginFormProps extends Omit<React.HTMLProps<HTMLFormElement>, '
passwordLabel?: string;
/** Value for the password */
passwordValue?: string;
/** Autocomplete value for the password input field */
passwordAutoComplete?: string;
/** Function that handles the onChange event for the password */
onChangePassword?: (event: React.FormEvent<HTMLInputElement>, value: string) => void;
/** Flag indicating if the password is valid */
Expand Down Expand Up @@ -66,11 +70,13 @@ export const LoginForm: React.FunctionComponent<LoginFormProps> = ({
helperTextIcon = null,
usernameLabel = 'Username',
usernameValue = '',
usernameAutoComplete,
onChangeUsername = () => undefined as any,
isValidUsername = true,
isPasswordRequired = true,
passwordLabel = 'Password',
passwordValue = '',
passwordAutoComplete,
onChangePassword = () => undefined as any,
isShowPasswordEnabled = false,
hidePasswordAriaLabel = 'Hide password',
Expand All @@ -92,6 +98,7 @@ export const LoginForm: React.FunctionComponent<LoginFormProps> = ({
type={passwordHidden ? 'password' : 'text'}
id="pf-login-password-id"
name="pf-login-password-id"
autoComplete={passwordAutoComplete}
validated={isValidPassword ? ValidatedOptions.default : ValidatedOptions.error}
value={passwordValue}
onChange={onChangePassword}
Expand All @@ -117,6 +124,7 @@ export const LoginForm: React.FunctionComponent<LoginFormProps> = ({
validated={isValidUsername ? ValidatedOptions.default : ValidatedOptions.error}
type="text"
name="pf-login-username-id"
autoComplete={usernameAutoComplete}
value={usernameValue}
onChange={onChangeUsername}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ describe('LoginForm', () => {
const mockFn = jest.fn();
const user = userEvent.setup();

render(<LoginForm onChangeUsername={mockFn} rememberMeLabel="Remember me" />);
render(
<LoginForm
onChangeUsername={mockFn}
rememberMeLabel="Remember me"
usernameAutoComplete="username"
passwordAutoComplete="current-password"
/>
);

expect(screen.getByLabelText(/username/i)).toHaveAttribute('autoComplete', 'username');
expect(screen.getByLabelText(/password/i)).toHaveAttribute('autoComplete', 'current-password');
await user.type(screen.getByText('Username'), 'updatedUserName');
expect(mockFn).toHaveBeenCalled();
});
Expand Down