-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add show password for input password
- Loading branch information
1 parent
78f5279
commit 8479096
Showing
4 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const inputsPassword = document.querySelectorAll('input[type="password"]'); | ||
|
||
if (inputsPassword) { | ||
inputsPassword.forEach(input => { | ||
const parent = document.createElement('div'); | ||
parent.classList.add('parent-password'); | ||
|
||
const icon = document.createElement('i'); | ||
icon.classList.add('bi', 'bi-eye-slash-fill', 'icon-password'); | ||
|
||
input.before(parent); | ||
parent.append(input); | ||
input.after(icon); | ||
|
||
icon.addEventListener('click', e => { | ||
const type = input.getAttribute('type') === 'password' ? 'text' : 'password'; | ||
input.setAttribute('type', type); | ||
|
||
if (type === 'password') { | ||
icon.classList.remove('bi-eye-fill'); | ||
icon.classList.add('bi-eye-slash-fill'); | ||
} else { | ||
icon.classList.remove('bi-eye-slash-fill'); | ||
icon.classList.add('bi-eye-fill'); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters