Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(LoginPage): added isPasswordRequired prop #11673

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Mash707
Copy link
Contributor

@Mash707 Mash707 commented Mar 13, 2025

Closes #11123

@patternfly-build
Copy link
Contributor

patternfly-build commented Mar 13, 2025

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Would you want to try writing a couple tests for this prop? One to check that the password field is required by default, and another to check that it is not required when isPasswordRequired is false.

@Mash707
Copy link
Contributor Author

Mash707 commented Mar 17, 2025

I'll work on writing the tests. Should I include the changes in this PR or open a followup? Also we don't have any examples showcasing the false state of the prop.

@thatblindgeye
Copy link
Contributor

You can include it in this PR. @andrew-ronaldson would we want to include an example for such a simple difference?

@andrew-ronaldson
Copy link
Collaborator

andrew-ronaldson commented Mar 17, 2025

Not sure if it needs an example. We can document the new prop with the existing example as a start

@Mash707
Copy link
Contributor Author

Mash707 commented Mar 17, 2025

@thatblindgeye I did some research and found out that passing the prop in FormGroup only changes the visual state of the field. This is not a solution we are looking for since it removes the ASTERISK symbol visually but the password field is still required.

<LabelComponent className={css(styles.formLabel)} {...(!isGroupOrRadioGroup && { htmlFor: fieldId })}>
<span className={css(styles.formLabelText)}>{label}</span>
{isRequired && (
<span className={css(styles.formLabelRequired)} aria-hidden="true">
{' '}
{ASTERISK}
</span>
)}
</LabelComponent>
<>&nbsp;&nbsp;</>
{isValidElement(labelHelp) && <span className={styles.formGroupLabelHelp}>{labelHelp}</span>}
</>
);

I am currently trying to find the component which handles the input state of password field.

@Mash707
Copy link
Contributor Author

Mash707 commented Mar 17, 2025

isPasswordRequired = true
image

isPasswordRequired = false
image

In both cases password is still required.
image

So the changes I have made in this PR are only visually updating the field

@Mash707 Mash707 force-pushed the add-password-prop-to-login-page branch from 48e3c69 to 27cfe4d Compare March 17, 2025 18:44
@Mash707
Copy link
Contributor Author

Mash707 commented Mar 17, 2025

const passwordInput = (
<TextInput
isRequired
type={passwordHidden ? 'password' : 'text'}
id="pf-login-password-id"
name="pf-login-password-id"
validated={isValidPassword ? ValidatedOptions.default : ValidatedOptions.error}
value={passwordValue}
onChange={onChangePassword}
/>
);

Needed to pass down the prop here too.

@Mash707
Copy link
Contributor Author

Mash707 commented Mar 17, 2025

I have added test case to ensure required field in password is present. Can't add test for not required since LoginPageDemo.tsx has isPasswordRequired=true by default.

@Mash707
Copy link
Contributor Author

Mash707 commented Mar 17, 2025

Currently I have not explicitly mentioned isPasswordRequired prop in any of the examples or demo(true by default). Should I include it?

@thatblindgeye
Copy link
Contributor

@Mash707 thanks for catching and looking into that.

For the test, we'd actually want to add a unit test for LoginForm specifically (in the packages/react-core/src/components/LoginPage/__tests__ directory).

We could add some verbiage to the MD file for the examples before the actual code between lines 32 and 34 in the MD). @edonehoo wdyt of something like "While the username field will always be required, you can make the password field optional by passing the isPasswordRequired property. By default a password will also be required." as an example description?

@edonehoo
Copy link
Contributor

@thatblindgeye how do you feel about swapping things around a little:

"By default, a login page requires users to enter both a username and a password into their respective fields. The username must always be a required field, but you can can make the password optional by passing the isPasswordRequired property to the <LoginForm>."

@Mash707
Copy link
Contributor Author

Mash707 commented Mar 18, 2025

I have added the test cases and also the explanatory text for the isPasswordRequired field.
I have squashed the commits.

@Mash707 Mash707 force-pushed the add-password-prop-to-login-page branch 2 times, most recently from b00a23b to 23d75ae Compare March 18, 2025 20:45
@@ -48,4 +48,16 @@ describe('LoginForm', () => {
const { asFragment } = render(<LoginForm isShowPasswordEnabled />);
expect(asFragment()).toMatchSnapshot();
});

test('LoginForm with isPasswordRequired', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the test descriptions, typically we try to keep a format of "Renders...."

So for these 2, maybe something like "Renders LoginForm with password field required by default" and "Renders LoginForm with password field not required when isPasswordRequired set to false"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the test description.

@Mash707 Mash707 force-pushed the add-password-prop-to-login-page branch from 23d75ae to 49b904a Compare March 19, 2025 19:46
@Mash707 Mash707 requested a review from thatblindgeye March 19, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LoginPage - add props to make username and password optional
5 participants