Auto-focus first input field of Login (as staff and patient) - #16605
Auto-focus first input field of Login (as staff and patient)#16605Rishav-Bagri wants to merge 1 commit into
Conversation
Greptile SummaryAdds automatic focus management to the login form.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable issues identified. The change only schedules focus for the active login mode’s fixed input ID, and missing elements are handled safely by optional chaining.
|
| Filename | Overview |
|---|---|
| src/components/Auth/Login.tsx | Adds a mode-dependent effect that focuses the first input after the corresponding staff or patient login form renders. |
Reviews (1): Last reviewed commit: "Auto-focus first input field of Login (a..." | Re-trigger Greptile
WalkthroughChangesLogin autofocus
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/Auth/Login.tsx`:
- Around line 130-135: Update the autofocus effect keyed by mode to derive the
target from the same effective login mode used by the rendered UI, including the
missing/invalid-mode fallback and disablePatientLogin staff-only case. Focus
username whenever staff UI is rendered; only target phone for the patient form.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 1c3b6426-fa5b-42c0-8cf9-7eb8dcd7fc59
📒 Files selected for processing (1)
src/components/Auth/Login.tsx
| // Autofocuses when switching tabs | ||
| useEffect(() => { | ||
| requestAnimationFrame(() => { | ||
| document.getElementById(mode === "staff" ? "username" : "phone")?.focus(); | ||
| }); | ||
| }, [mode]); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Derive the focus target from the rendered login mode.
The UI falls back to staff mode when mode is missing/invalid, and disablePatientLogin also renders staff-only UI. This effect treats every value except exact "staff" as patient, so it searches for #phone while the staff form is rendered and fails to autofocus the username.
+ const activeMode =
+ !disablePatientLogin && mode === "patient" ? "patient" : "staff";
+
// Autofocuses when switching tabs
useEffect(() => {
- requestAnimationFrame(() => {
- document.getElementById(mode === "staff" ? "username" : "phone")?.focus();
+ const frame = requestAnimationFrame(() => {
+ document
+ .getElementById(activeMode === "staff" ? "username" : "phone")
+ ?.focus();
});
- }, [mode]);
+ return () => cancelAnimationFrame(frame);
+ }, [activeMode]);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Autofocuses when switching tabs | |
| useEffect(() => { | |
| requestAnimationFrame(() => { | |
| document.getElementById(mode === "staff" ? "username" : "phone")?.focus(); | |
| }); | |
| }, [mode]); | |
| const activeMode = | |
| !disablePatientLogin && mode === "patient" ? "patient" : "staff"; | |
| // Autofocuses when switching tabs | |
| useEffect(() => { | |
| const frame = requestAnimationFrame(() => { | |
| document | |
| .getElementById(activeMode === "staff" ? "username" : "phone") | |
| ?.focus(); | |
| }); | |
| return () => cancelAnimationFrame(frame); | |
| }, [activeMode]); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/Auth/Login.tsx` around lines 130 - 135, Update the autofocus
effect keyed by mode to derive the target from the same effective login mode
used by the rendered UI, including the missing/invalid-mode fallback and
disablePatientLogin staff-only case. Focus username whenever staff UI is
rendered; only target phone for the patient form.
Proposed Changes
Fixes #16604
Screen.Recording.2026-07-28.170709.mp4
Tagging: @ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit