Skip to content

Commit afba31a

Browse files
committed
Fix issue with password visibility toggle
The password visibility toggle was displayed far to the right of the screen instead of in the password input field because the parent div was not the password field, but also contained the label.
1 parent 5031a86 commit afba31a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

app/views/layouts/session.html.erb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
// Password visibility toggle (if needed)
4949
const passwordFields = document.querySelectorAll('input[type="password"]');
5050
passwordFields.forEach(field => {
51+
// Create wrapper div for the input field
52+
const wrapper = document.createElement('div');
53+
wrapper.style.position = 'relative';
54+
wrapper.style.display = 'block';
55+
56+
// Insert wrapper before the field and move field into wrapper
57+
field.parentNode.insertBefore(wrapper, field);
58+
wrapper.appendChild(field);
59+
60+
// Create toggle button
5161
const toggleBtn = document.createElement('button');
5262
toggleBtn.type = 'button';
5363
toggleBtn.className = 'btn btn-link position-absolute end-0 top-50 translate-middle-y me-3';
@@ -56,8 +66,8 @@
5666
toggleBtn.style.border = 'none';
5767
toggleBtn.style.background = 'none';
5868

59-
field.parentElement.style.position = 'relative';
60-
field.parentElement.appendChild(toggleBtn);
69+
// Append button to wrapper
70+
wrapper.appendChild(toggleBtn);
6171

6272
toggleBtn.addEventListener('click', function() {
6373
const type = field.getAttribute('type') === 'password' ? 'text' : 'password';

0 commit comments

Comments
 (0)