Skip to content

Commit

Permalink
fix: DAH-2789 Fix password show/hide functionality (#2401)
Browse files Browse the repository at this point in the history
* fix: password show and hide functionality

* test: update snapshots

* fix: remove spaces check
  • Loading branch information
chadbrokaw authored Nov 7, 2024
1 parent 4d952dd commit 9229d73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,12 @@ exports[`<AccountSettingsPage /> when the user is signed in resize events 1`] =
class="field"
>
<input
id="showPassword"
name="showPassword"
id="currentPassword-showPassword"
name="currentPassword-showPassword"
type="checkbox"
/>
<label
for="showPassword"
for="currentPassword-showPassword"
>
Show password
</label>
Expand Down Expand Up @@ -661,12 +661,12 @@ exports[`<AccountSettingsPage /> when the user is signed in resize events 1`] =
>
<input
checked=""
id="showPassword"
name="showPassword"
id="password-showPassword"
name="password-showPassword"
type="checkbox"
/>
<label
for="showPassword"
for="password-showPassword"
>
Show password
</label>
Expand Down Expand Up @@ -1390,12 +1390,12 @@ exports[`<AccountSettingsPage /> when the user is signed in resize events 1`] =
class="field"
>
<input
id="showPassword"
name="showPassword"
id="currentPassword-showPassword"
name="currentPassword-showPassword"
type="checkbox"
/>
<label
for="showPassword"
for="currentPassword-showPassword"
>
Show password
</label>
Expand Down Expand Up @@ -1474,12 +1474,12 @@ exports[`<AccountSettingsPage /> when the user is signed in resize events 1`] =
>
<input
checked=""
id="showPassword"
name="showPassword"
id="password-showPassword"
name="password-showPassword"
type="checkbox"
/>
<label
for="showPassword"
for="password-showPassword"
>
Show password
</label>
Expand Down Expand Up @@ -2260,12 +2260,12 @@ exports[`<AccountSettingsPage /> when the user is signed in resize events 2`] =
class="field"
>
<input
id="showPassword"
name="showPassword"
id="currentPassword-showPassword"
name="currentPassword-showPassword"
type="checkbox"
/>
<label
for="showPassword"
for="currentPassword-showPassword"
>
Show password
</label>
Expand Down Expand Up @@ -2344,12 +2344,12 @@ exports[`<AccountSettingsPage /> when the user is signed in resize events 2`] =
>
<input
checked=""
id="showPassword"
name="showPassword"
id="password-showPassword"
name="password-showPassword"
type="checkbox"
/>
<label
for="showPassword"
for="password-showPassword"
>
Show password
</label>
Expand Down Expand Up @@ -3073,12 +3073,12 @@ exports[`<AccountSettingsPage /> when the user is signed in resize events 2`] =
class="field"
>
<input
id="showPassword"
name="showPassword"
id="currentPassword-showPassword"
name="currentPassword-showPassword"
type="checkbox"
/>
<label
for="showPassword"
for="currentPassword-showPassword"
>
Show password
</label>
Expand Down Expand Up @@ -3157,12 +3157,12 @@ exports[`<AccountSettingsPage /> when the user is signed in resize events 2`] =
>
<input
checked=""
id="showPassword"
name="showPassword"
id="password-showPassword"
name="password-showPassword"
type="checkbox"
/>
<label
for="showPassword"
for="password-showPassword"
>
Show password
</label>
Expand Down
8 changes: 5 additions & 3 deletions app/javascript/pages/account/components/PasswordFieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ interface PasswordFieldProps extends Omit<FieldProps, "type" | "postInputContent
const PasswordField = ({ passwordVisibilityDefault = false, ...props }: PasswordFieldProps) => {
const [showPassword, setShowPassword] = React.useState(passwordVisibilityDefault)

const showPasswordId = `${props.name}-showPassword`

return (
<>
<Field
Expand All @@ -143,12 +145,12 @@ const PasswordField = ({ passwordVisibilityDefault = false, ...props }: Password
<div className="field">
<input
type="checkbox"
id="showPassword"
name="showPassword"
id={showPasswordId}
name={showPasswordId}
checked={showPassword}
onChange={() => setShowPassword(!showPassword)}
/>
<label htmlFor="showPassword">{t("label.showPassword")}</label>
<label htmlFor={showPasswordId}>{t("label.showPassword")}</label>
</div>
</>
)
Expand Down

0 comments on commit 9229d73

Please sign in to comment.