Skip to content

Reopen: Fix user reactivity in Navbar and improve password focus handling (prev. PR #54) #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chabdulrahmn
Copy link

@chabdulrahmn chabdulrahmn commented Apr 23, 2025

This PR is a refreshed version of my previous contribution #54, which was closed due to my unavailability and unresolved merge conflicts. I’ve now resolved all conflicts, refined the changes, and ensured full compatibility with the latest codebase.


✅ What's Updated

🔁 Refactor: Make user reactive using computed and simplify prop passing

  • Converted user from a static variable to a computed property for better reactivity.
  • Fixes the issue where updated user data (e.g. after profile edits) wasn't reflected in the Navbar unless the page was refreshed.
  • Updated prop binding syntax from :user="user" to shorthand :user for cleaner template usage.

🛠️ Fix: Properly focus password input on error in Delete User modal

  • Removed passwordInput ref and reliance on $el to access native <input> inside the Input component.
  • Fixed TypeError: passwordInput.value?.focus is not a function caused by trying to focus the component instance instead of the actual input.
  • Replaced it with native DOM access using formElement.password inside the onError callback.
  • Used nextTick() to ensure DOM is updated before calling .focus().

💡 Why it matters

These changes enhance both UX and code maintainability:

  • The Navbar now dynamically reflects authenticated user changes without reloads.
  • The Delete User modal now reliably focuses the password field on validation error — even when using shadcn-vue components.

🎥 Visual Demos (Before → After)

Here’s a visual comparison of the previous behavior vs. the updated experience:

🔁 Navbar user data updates automatically after profile changes (no page refresh needed)

Navbar

🛠️ Password input now correctly focuses on error

Password Modal


📎 Related

- Switched `user` from a static variable to a computed property to enable reactivity.
  This ensures updated user data (e.g. after profile update) is reflected in the NavBar
  without requiring a full page refresh.
- Updated prop binding syntax from `:user="user"` to shorthand `:user`.
- Removed `passwordInput` ref and reliance on `$el` to access the input field inside the `Input` component.
- Fixed `TypeError` caused by calling `focus()` on the component instance.
- Now focusing the password input via `formElement.password` in the form's submit error handler.
- Used `nextTick` to ensure the DOM is updated before focusing.
- This approach is cleaner, avoids reliance on component internals, and works reliably with shadcn-vue components.
@tnylea
Copy link
Contributor

tnylea commented Apr 25, 2025

Thanks @chabdulrahmn for the detailed PR and the visuals. I just tested your branch out on my end and it works great.

Thanks again for the PR 👏

@tnylea tnylea added the Approved Approved for merge label Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Approved for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants