Skip to content
Merged
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
9 changes: 8 additions & 1 deletion src/js/visible-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ 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 {textHide, textShow} = button.dataset;

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