Conversation
There was a problem hiding this comment.
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
AutofocusJS behavior and.autofocus-based focus triggers; migrate remaining usages to nativeautofocus. - 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.
2748b3e to
ca018ff
Compare
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.
ca018ff to
1c7c38a
Compare
jrauh01
left a comment
There was a problem hiding this comment.
I have made the following observations:
- 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.
- If you are not authenticated and an error is rendered via
guest-error.phtmlthe 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>'; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Are the missing quotes intentional?
| tabindex=-1 | |
| tabindex="-1" |
|
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. |
The native attribute
autofocusis nowadays the better alternative to our legacy.autofocusimplementation. 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