Skip to content

Fix focus on login password #5504

Open
nilmerg wants to merge 7 commits intomainfrom
fix/autofocus-on-login-password-5503
Open

Fix focus on login password #5504
nilmerg wants to merge 7 commits intomainfrom
fix/autofocus-on-login-password-5503

Conversation

@nilmerg
Copy link
Copy Markdown
Member

@nilmerg nilmerg commented May 8, 2026

The native attribute autofocus is nowadays the better alternative to our legacy .autofocus implementation. Also this was seldomly used elsewhere. Except in the director, which handles it manually anyway. It is now gone for good.

In case we ever need something similar, we should re-introduce it but properly integrate it with the default focus handling. But now it's not the time and no real need for this.

A small bonus of this change is that error messages are now copyable to clipboard with a single click.

The related issue is fixed because our default focus preservation now doesn't kick in because the login form uses the native attribute on the username field.

fixes #5503

@nilmerg nilmerg added this to the 2.14.0 milestone May 8, 2026
@nilmerg nilmerg requested a review from Copilot May 8, 2026 09:22
@nilmerg nilmerg self-assigned this May 8, 2026
@cla-bot cla-bot Bot added the cla/signed label May 8, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the legacy .autofocus-based focus behavior in favor of native HTML autofocus, adjusts AJAX focus preservation to avoid overriding native autofocus, and adds a copy-to-clipboard affordance to the error page (issue #5503).

Changes:

  • Remove the Autofocus JS behavior and .autofocus-based focus triggers; migrate remaining usages to native autofocus.
  • Update form-submit focus preservation logic in the JS loader to avoid forcing focus when a form contains an autofocus element.
  • Wrap error output in a clipboard-friendly container and add a copy-to-clipboard button.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
public/js/icinga/loader.js Adjusts focus preservation on XHR form submissions to not override native autofocus.
public/js/icinga/behavior/form.js Removes .autofocus from the “do not change content if focused” selector set.
public/js/icinga/behavior/autofocus.js Deletes legacy autofocus behavior implementation.
modules/setup/application/forms/WelcomePage.php Replaces .autofocus class with native autofocus attribute.
library/Icinga/Web/Widget/FilterEditor.php Removes .autofocus injection hack when adding filters.
library/Icinga/Web/JavaScript.php Stops shipping the removed autofocus behavior script.
application/views/scripts/error/error.phtml Adds a copy-to-clipboard button and wrapper around error messages.
application/layouts/scripts/layout.phtml Changes web-app capability meta tag.
application/forms/ConfirmRemovalForm.php Removes submit-button .autofocus injection override.
application/forms/Authentication/LoginForm.php Uses native autofocus for username field instead of .autofocus.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread public/js/icinga/loader.js Outdated
Comment thread application/forms/Authentication/LoginForm.php
Comment thread application/layouts/scripts/layout.phtml Outdated
Comment thread application/views/scripts/error/error.phtml
@nilmerg nilmerg force-pushed the fix/autofocus-on-login-password-5503 branch from 2748b3e to ca018ff Compare May 8, 2026 09:40
nilmerg added 7 commits May 8, 2026 11:45
Besides that this is a destructive operation which shouldn't
get automatic focus… our native way to adhere to WCAG standards
is by focusing the newly rendered container which suffices.
Hopefully users will now always include the first message
in reports and not only the stacktrace

Hopefully users will now always include the first message
in reports and not only the stacktrace……
Didn't notice that was working as intended now, but it makes
zero sense anyway as both functions are distinct and either
cannot replace the other -.-
There are none anymore and the implementation is going
to be removed from the framework until we have a better
idea how or whether to still support autofocusing.
It didn't work anyway and is now obsolete given that there's
a `autofocus` attribute widely supported by browsers. The catch
however is, that this only works upon page load. But all still
relevant cases where autofocus is suited are in fact page loads.

In case we ever need something similar, we should re-introduce
it but properly integrate it with the default focus handling.
But now it's not the time and no real need for this.
If a form uses the native autofocus, it seems it wants to guide
the user. So the first visit respects the autofocus, so the
element is either still focused upon submit or another one.
Either way, the default focus preservation ensures that whatever
is in focus will retain it if necessary and if not, the content
will probably fundamentally change and no force focus is required.
With the only remaining cases, login and setup, this is true.
Another upcoming case is the 2FA flow, where it is true as well.
@nilmerg nilmerg force-pushed the fix/autofocus-on-login-password-5503 branch from ca018ff to 1c7c38a Compare May 8, 2026 09:45
@nilmerg nilmerg requested a review from jrauh01 May 8, 2026 09:46
Copy link
Copy Markdown
Contributor

@jrauh01 jrauh01 left a comment

Choose a reason for hiding this comment

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

I have made the following observations:

  1. If the login form is submitted via the enter key the password field preserves focus, but if the form is submitted via a click on the button the focus will preserve on the button. I think this is basically what the change is intended to do, but it "breaks" the password-field-keeps-focus logic we had before.
  2. If you are not authenticated and an error is rendered via guest-error.phtml the copy-to-clipboard button is not visible to interact with.

echo '<p tabindex="-1" class="autofocus error-message">' . nl2br($this->escape($message)) . '</p>'
echo '<p class="error-message">' . nl2br($this->escape($message)) . '<br></p>'
. '<hr>'
. '<pre>' . $this->escape($stackTraces[$i]) . '</pre>';
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.

I think a <br> would be nice here. Multiple stacktraces are currently copied to clipboard as follows:

outer
#0 /usr/share/icinga-php/vendor/vendor/icinga/zf1/library/Zend/Controller/Action.php(528): Icinga\Controllers\AccountController->indexAction()
#1 /icingaweb2/library/Icinga/Web/Controller/Dispatcher.php(78): Zend_Controller_Action->dispatch(String)
#2 /usr/share/icinga-php/vendor/vendor/icinga/zf1/library/Zend/Controller/Front.php(954): Icinga\Web\Controller\Dispatcher->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#3 /icingaweb2/library/Icinga/Application/Web.php(296): Zend_Controller_Front->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#4 /icingaweb2/library/Icinga/Application/webrouter.php(107): Icinga\Application\Web->dispatch()
#5 /icingaweb2/public/index.php(6): require_once(String)
#6 {main}inner
#0 /usr/share/icinga-php/vendor/vendor/icinga/zf1/library/Zend/Controller/Action.php(528): Icinga\Controllers\AccountController->indexAction()
#1 /icingaweb2/library/Icinga/Web/Controller/Dispatcher.php(78): Zend_Controller_Action->dispatch(String)
#2 /usr/share/icinga-php/vendor/vendor/icinga/zf1/library/Zend/Controller/Front.php(954): Icinga\Web\Controller\Dispatcher->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#3 /icingaweb2/library/Icinga/Application/Web.php(296): Zend_Controller_Front->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#4 /icingaweb2/library/Icinga/Application/webrouter.php(107): Icinga\Application\Web->dispatch()
#5 /icingaweb2/public/index.php(6): require_once(String)
#6 {main}

<button type="button"
class="copy-to-clipboard"
data-icinga-clipboard
tabindex=-1
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.

Are the missing quotes intentional?

Suggested change
tabindex=-1
tabindex="-1"

@jrauh01
Copy link
Copy Markdown
Contributor

jrauh01 commented May 8, 2026

I also wanted to document what we discussed in person earlier. This change prevents the token input from being automatically focused in the upcoming two-factor authentication feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No autofocus on password element

3 participants