Skip to content

Commit

Permalink
[web] Allow disabling PasswordAndConfirmation input
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Dec 5, 2022
1 parent dad1b62 commit a5c3937
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion web/src/components/core/PasswordAndConfirmationInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
TextInput
} from "@patternfly/react-core";

const PasswordAndConfirmationInput = ({ value, onChange, onValidation }) => {
const PasswordAndConfirmationInput = ({ value, onChange, onValidation, isDisabled }) => {
const [confirmation, setConfirmation] = useState(value || "");
const [error, setError] = useState("");

Expand Down Expand Up @@ -61,6 +61,7 @@ const PasswordAndConfirmationInput = ({ value, onChange, onValidation }) => {
type="password"
aria-label="User password"
value={value}
isDisabled={isDisabled}
onChange={onChangeValue}
onBlur={() => validate(value, confirmation)}
/>
Expand All @@ -77,6 +78,7 @@ const PasswordAndConfirmationInput = ({ value, onChange, onValidation }) => {
type="password"
aria-label="User password confirmation"
value={confirmation}
isDisabled={isDisabled}
onChange={onChangeConfirmation}
onBlur={() => validate(value, confirmation)}
validated={error === "" ? "default" : "error"}
Expand Down
16 changes: 14 additions & 2 deletions web/src/components/core/PasswordAndConfirmationInput.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe("when the passwords do not match", () => {
});

it("uses the given password value for confirmation too", async () => {
const { user } = plainRender(
<PasswordAndConfirmationInput value={"12345"} />
plainRender(
<PasswordAndConfirmationInput value="12345" />
);

const passwordInput = screen.getByLabelText("Password");
Expand All @@ -48,3 +48,15 @@ it("uses the given password value for confirmation too", async () => {
expect(passwordInput.value).toEqual("12345");
expect(passwordInput.value).toEqual(confirmationInput.value);
});

it("disables both, password and confirmation, when isDisabled prop is given", async () => {
plainRender(
<PasswordAndConfirmationInput value="12345" isDisabled />
);

const passwordInput = screen.getByLabelText("Password");
const confirmationInput = screen.getByLabelText("Password confirmation");

expect(passwordInput).toBeDisabled();
expect(confirmationInput).toBeDisabled();
});
2 changes: 1 addition & 1 deletion web/src/components/storage/ProposalSettingsForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export default function ProposalSettingsForm({ id, proposal, onSubmit, onValidat
onChange={onLvmChange}
/>
<Fieldset
isDisabled={!state.encryption}
legend={
<Switch
id="encryption"
Expand All @@ -105,6 +104,7 @@ export default function ProposalSettingsForm({ id, proposal, onSubmit, onValidat
<PasswordAndConfirmationInput
id="encryptionPassword"
value={state.encryptionPassword}
isDisabled={!state.encryption}
onChange={onPasswordChange}
onValidation={onEncryptionValidate}
/>
Expand Down

0 comments on commit a5c3937

Please sign in to comment.