8000 Fix "try another way" link by db6edr · Pull Request #981 · keycloakify/keycloakify · GitHub
[go: up one dir, main page]

Skip to content

Fix "try another way" link - #981

Merged
garronej merged 1 commit into
keycloakify:mainfrom
db6edr:fix-912_try-another-way_broken
Jan 11, 2026
Merged

garronej merged 1 commit into
keycloakify:mainfrom
db6edr:fix-912_try-another-way_broken

Conversation

@db6edr
@db6edr db6edr commented Jan 9, 2026 •
Copy link
Copy Markdown
Contributor

Prevent default action of navigation event

Fixes #912

Summary by CodeRabbit

  • Bug Fixes
    • Prevented unexpected navigation when activating form-related links, ensuring the link interaction no longer triggers default navigation while still submitting the associated form reliably.
    • No changes to public exports or external interfaces.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
coderabbitai Bot commented Jan 9, 2026 •
Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Updated the login template's anchor click handler to accept the click event, call event.preventDefault(), and submit the surrounding form via requestSubmit(), preventing default navigation/download while preserving form submission.

Changes

Cohort / File(s) Summary
Login form link behavior
src/login/Template.tsx
Anchor onClick now accepts the event, calls event.preventDefault(), and invokes form.requestSubmit() instead of relying on default href navigation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

🐰 A little hop, a gentle fix,
I caught the click that played its tricks.
No file falls when users play—
I stop the drift and let forms stay.
Hooray for clicks that go the right way! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: fixing the broken "try another way" link behavior.
Linked Issues check ✅ Passed The code change adds preventDefault() and requestSubmit() to the anchor element, directly addressing issue #912's requirement to restore correct navigation behavior for the "Try another method" link.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the broken "try another way" link in Template.tsx; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between adad823 and 26635d0.

📒 Files selected for processing (1)
  • src/login/Template.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/login/Template.tsx

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/login/Template.tsx (1)

159-168: Restore keyboard accessibility for the "Try another way" link.

Removing the href attribute breaks keyboard navigation and screen reader compatibility. Without an href, the anchor element is not keyboard-focusable by default and may not be recognized as an interactive element by assistive technologies, preventing keyboard users from accessing this functionality.

Consider one of these solutions:

Solution 1 (Recommended): Add href="#" and role="button" while keeping the click handler:

 <a
+    href="#"
+    role="button"
     id="try-another-way"
      => {
         document.forms["kc-select-try-another-way-form" as never].requestSubmit();
         event.preventDefault();
         return false;
     }}
 >
     {msg("doTryAnotherWay")}
 </a>

Solution 2 (Alternative): Replace with a button element styled as a link:

-<a
+<button
+    type="button"
+    className={kcClsx("kcFormButtonClass")} // or appropriate link-styled class
     id="try-another-way"
      => {
         document.forms["kc-select-try-another-way-form" as never].requestSubmit();
         event.preventDefault();
-        return false;
     }}
 >
     {msg("doTryAnotherWay")}
-</a>
+</button>
🧹 Nitpick comments (1)
src/login/Template.tsx (1)

161-165: Consider simplifying the click handler.

Two optional improvements:

  1. The return false statement on Line 164 is redundant since event.preventDefault() is already called. In React, returning false doesn't prevent default behavior like it does in jQuery.

  2. The type assertion as never on Line 162 is a workaround for TypeScript's forms collection typing. Consider using a more explicit approach:

♻️ Suggested refactor
  => {
-    document.forms["kc-select-try-another-way-form" as never].requestSubmit();
+    const form = document.getElementById("kc-select-try-another-way-form") as HTMLFormElement;
+    form.requestSubmit();
     event.preventDefault();
-    return false;
 }}

Or if keeping the forms collection access:

  => {
-    document.forms["kc-select-try-another-way-form" as never].requestSubmit();
+    (document.forms.namedItem("kc-select-try-another-way-form") as HTMLFormElement).requestSubmit();
     event.preventDefault();
-    return false;
 }}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daa2698 and adad823.

📒 Files selected for processing (1)
  • src/login/Template.tsx
🔇 Additional comments (1)
src/login/Template.tsx (1)

162-162: Verify your project's browser support policy for requestSubmit().

The requestSubmit() method is supported in Chrome 76+, Firefox 75+, and Safari 16+. If your project requires compatibility with older browsers, consider this fallback pattern:

Fallback for older browsers
  => {
-    document.forms["kc-select-try-another-way-form" as never].requestSubmit();
+    const form = document.getElementById("kc-select-try-another-way-form") as HTMLFormElement;
+    if (form.requestSubmit) {
+        form.requestSubmit();
+    } else {
+        form.submit();
+    }
     event.preventDefault();
     return false;
 }}

Note: Using submit() as a fallback won't trigger form validation or submit event listeners, but ensures basic functionality.

Prevent default action of navigation event

Fixes keycloakify#912
@db6edr
db6edr force-pushed the fix-912_try-another-way_broken branch from adad823 to 26635d0 Compare January 9, 2026 09:52
@garronej
Copy link
Copy Markdown
Collaborator

Thank you 🙏🏻 !

@allcontributors add @db6edr for code

@allcontributors
Copy link
Copy Markdown
Contributor

@garronej

I've put up a pull request to add @db6edr! 🎉

@garronej
garronej merged commit ec6c940 into keycloakify:main Jan 11, 2026
1 check passed
@db6edr
db6edr deleted the fix-912_try-another-way_broken branch January 11, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Try another method link broken

2 participants

0