@@ -30,8 +30,8 @@ import IconHidePassword from '../assets/icon/eye-off.svg'
3030 />
3131 <label for =" login-password" >Password</label >
3232 <div class =" icons" title =" Toggle password visibility" >
33- <IconShowPassword id =" show-password" />
34- <IconHidePassword id =" hide-password" />
33+ <IconShowPassword class =" show-password" />
34+ <IconHidePassword class =" hide-password" />
3535 </div >
3636 </div >
3737 </div >
@@ -67,25 +67,35 @@ import IconHidePassword from '../assets/icon/eye-off.svg'
6767 </div >
6868
6969 <div class =" form-field" >
70- <input
71- type =" password"
72- id =" register-password"
73- name =" register-password"
74- required
75- />
76- <label for =" register-password" >Password</label >
70+ <div class =" input-with-icon" >
71+ <input
72+ type =" password"
73+ id =" register-password"
74+ name =" register-password"
75+ required
76+ />
77+ <label for =" register-password" >Password</label >
78+ <div class =" icons" title =" Toggle password visibility" >
79+ <IconShowPassword class =" show-password" />
80+ <IconHidePassword class =" hide-password" />
81+ </div >
82+ </div >
7783 </div >
7884
7985 <div class =" form-field" >
80- <input
81- type =" password"
82- id =" register-password-confirm"
83- name =" register-password-confirm"
84- required
85- />
86- <label for =" register-password-confirm"
87- >Confirm Password</label
88- >
86+ <div class =" input-with-icon" >
87+ <input
88+ type =" password"
89+ id =" register-password-password"
90+ name =" register-password-password"
91+ required
92+ />
93+ <label for =" register-password-password" >Password</label >
94+ <div class =" icons" title =" Toggle password visibility" >
95+ <IconShowPassword class =" show-password" />
96+ <IconHidePassword class =" hide-password" />
97+ </div >
98+ </div >
8999 </div >
90100
91101 <button type =" submit" >Register</button >
@@ -171,6 +181,14 @@ import IconHidePassword from '../assets/icon/eye-off.svg'
171181 border-bottom-color: var(--color-secondary);
172182 }
173183
184+ .hide-password {
185+ display: none;
186+ }
187+
188+ .show-password {
189+ color: #888;
190+ }
191+
174192 .icons {
175193 cursor: pointer;
176194 }
@@ -187,14 +205,6 @@ import IconHidePassword from '../assets/icon/eye-off.svg'
187205 width: 100%;
188206 }
189207
190- #hide-password {
191- display: none;
192- }
193-
194- #show-password {
195- color: #888;
196- }
197-
198208 /* Pseudo-classes */
199209
200210 button[type='submit']:hover {
@@ -213,17 +223,11 @@ import IconHidePassword from '../assets/icon/eye-off.svg'
213223 const registerSection = document.getElementById('register')
214224 const loginLink = document.getElementById('register-link')
215225 const registerLink = document.getElementById('login-link')
216- const passwordInput = document.getElementById('login-password')
217- const showIcon = document.getElementById('show-password')
218- const hideIcon = document.getElementById('hide-password')
219226
227+ // Maintain label position on filled inputs
220228 document.querySelectorAll('.form-field input').forEach((input) => {
221229 const updateFilled = () => {
222- if (input.value.trim() !== '') {
223- input.classList.add('filled')
224- } else {
225- input.classList.remove('filled')
226- }
230+ input.classList.toggle('filled', input.value.trim() !== '')
227231 }
228232
229233 input.addEventListener('input', updateFilled)
@@ -232,13 +236,7 @@ import IconHidePassword from '../assets/icon/eye-off.svg'
232236 updateFilled()
233237 })
234238
235- function togglePasswordVisibility() {
236- const isHidden = passwordInput.type === 'password'
237- passwordInput.type = isHidden ? 'text' : 'password'
238- showIcon.style.display = isHidden ? 'none' : 'inline'
239- hideIcon.style.display = isHidden ? 'inline' : 'none'
240- }
241-
239+ // Flip between login and register forms
242240 loginLink.addEventListener('click', (e) => {
243241 e.preventDefault()
244242 loginSection.style.display = 'none'
@@ -251,6 +249,30 @@ import IconHidePassword from '../assets/icon/eye-off.svg'
251249 loginSection.style.display = 'flex'
252250 })
253251
254- showIcon.addEventListener('click', togglePasswordVisibility)
255- hideIcon.addEventListener('click', togglePasswordVisibility)
252+ // Toggle visibility for password fields
253+ document.querySelectorAll('.icons').forEach((iconContainer) => {
254+ const section = iconContainer.closest('section')
255+ const passwordInputs = section.querySelectorAll(
256+ 'input[type="password"], input[type="text"]'
257+ )
258+ const showIcons = section.querySelectorAll('.show-password')
259+ const hideIcons = section.querySelectorAll('.hide-password')
260+
261+ const toggle = () => {
262+ const isHidden = [...passwordInputs].some(
263+ (input) => input.type === 'password'
264+ )
265+ passwordInputs.forEach((input) => {
266+ input.type = isHidden ? 'text' : 'password'
267+ })
268+ showIcons.forEach((icon) => {
269+ icon.style.display = isHidden ? 'none' : 'inline'
270+ })
271+ hideIcons.forEach((icon) => {
272+ icon.style.display = isHidden ? 'inline' : 'none'
273+ })
274+ }
275+
276+ iconContainer.addEventListener('click', toggle)
277+ })
256278</script >
0 commit comments