Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion src/js/visible-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ const initVisiblePassword = () => {
const visiblePasswordList = document.querySelectorAll(visiblePasswordMap.visiblePassword);

visiblePasswordList.forEach((input: HTMLInputElement) => {
const button = input?.nextElementSibling;
const button = input?.nextElementSibling as HTMLElement;

button?.addEventListener('click', () => {
const newType = input.getAttribute('type') === 'text' ? 'password' : 'text';
input.setAttribute('type', newType);
button.setAttribute('aria-expanded', newType === 'text' ? 'true' : 'false');

const icon = button.firstElementChild;

if (icon) {
icon.innerHTML = newType === 'text' ? 'visibility_off' : 'visibility';

const textShow = button.dataset.textShow;
const textHide = button.dataset.textHide;
Copy link
Contributor

@kpodemski kpodemski Jun 13, 2023

Choose a reason for hiding this comment

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

Suggested change
const textHide = button.dataset.textHide;
const { textHide, textShow } = button.dataset;

that should do it with eslint errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated!


if (textShow && textHide) {
button.setAttribute('aria-label', newType === 'text' ? textHide : textShow);
}
}
});
});
Expand Down
6 changes: 4 additions & 2 deletions templates/_partials/form-fields.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@
class="btn btn-primary"
type="button"
data-action="show-password"
data-text-show="{l s='Show' d='Shop.Theme.Actions'}"
data-text-hide="{l s='Hide' d='Shop.Theme.Actions'}"
data-text-show="{l s='Show Password' d='Shop.Theme.Actions'}"
data-text-hide="{l s='Hide Password' d='Shop.Theme.Actions'}"
aria-label="{l s='Show Password' d='Shop.Theme.Actions'}"
aria-expanded="false"
>
<i class="material-icons">visibility</i>
</button>
Expand Down
12 changes: 8 additions & 4 deletions templates/customer/password-new.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
class="btn btn-primary"
type="button"
data-action="show-password"
data-text-show="{l s='Show' d='Shop.Theme.Actions'}"
data-text-hide="{l s='Hide' d='Shop.Theme.Actions'}"
data-text-show="{l s='Show Password' d='Shop.Theme.Actions'}"
data-text-hide="{l s='Hide Password' d='Shop.Theme.Actions'}"
aria-label="{l s='Show Password' d='Shop.Theme.Actions'}"
aria-expanded="false"
>
<i class="material-icons">visibility</i>
</button>
Expand All @@ -52,8 +54,10 @@
class="btn btn-primary"
type="button"
data-action="show-password"
data-text-show="{l s='Show' d='Shop.Theme.Actions'}"
data-text-hide="{l s='Hide' d='Shop.Theme.Actions'}"
data-text-show="{l s='Show Password' d='Shop.Theme.Actions'}"
data-text-hide="{l s='Hide Password' d='Shop.Theme.Actions'}"
aria-label="{l s='Show Password' d='Shop.Theme.Actions'}"
aria-expanded="false"
>
<i class="material-icons">visibility</i>
</button>
Expand Down