Replace autofocus with data-global-init="initInputAutoFocusEnd".#34252
Replace autofocus with data-global-init="initInputAutoFocusEnd".#34252kerwin612 wants to merge 1 commit intogo-gitea:mainfrom
autofocus with data-global-init="initInputAutoFocusEnd".#34252Conversation
|
For most pages, the "autofocus" or "initInputAutoFocusEnd" seems abused. I would suggest either leave autofocus as-is, or just remove it, but don't make it more complex than it should be. |
My viewpoints are as follows: As I'm writing this, I'm thinking about whether we can add a utility function in the Go code:
func inputAttrs(value string) string {
if value != "" {
return "data-global-init=\"initInputAutoFocusEnd\""
}
return "autofocus"
}
<input {{inputAttrs value}}/>This is just a preliminary idea. My point is that we should either not implement autofocus at all or implement it properly. We can't do a half - baked job. |
Why they should be focused? Does end user would really like to input anything in most cases? Take GitHub as an example, most input doesn't get "autofocus" on most pages. |
wxiaoguang
left a comment
There was a problem hiding this comment.
Don't make changes which you don't understand.
Yes, so my view is that if the |
159ebec to
c0f8c62
Compare
| <span class="text red tw-hidden" id="name-change-redirect-prompt"> {{ctx.Locale.Tr "settings.change_username_redirect_prompt"}}</span> | ||
| </label> | ||
| <input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (not .SignedUser.IsLocal) ($.UserDisabledFeatures.Contains "change_username") .IsReverseProxy}}disabled{{end}} maxlength="40"> | ||
| <input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" data-global-init="initInputAutoFocusEnd" required {{if or (not .SignedUser.IsLocal) ($.UserDisabledFeatures.Contains "change_username") .IsReverseProxy}}disabled{{end}} maxlength="40"> |
There was a problem hiding this comment.
Why you assume that when a user goes to the "settings profile" page, they are highly likely going to change their username?
If they don't want to change their username, why the input should be auto-focused?
There was a problem hiding this comment.
The starting point is as follows:
I was about to edit my username. When I came to this page, the input box for the username had already gained focus because the autofocus attribute was added to the input element.
Then:
① I had to click at the end of the input box, press the Backspace key to delete the original username, and then enter a new one.
② Or, I could press the Delete key to delete the original username and then enter a new one.
At least in my opinion, ordinary people use the Backspace key far more frequently than the Delete key. So I thought it was unreasonable, and that's why I naturally submitted this PR.
There was a problem hiding this comment.
I have no interest to do more arguments.
In short: GitHub doesn't do so, Discord doesn't do so, I guess GitLab doesn't do so either.
I do not see any website do so.
There was a problem hiding this comment.
- It is NOT username
- It is NOT autofocus or initInputAutoFocusEnd. They WILL NOT WORK because the element is hidden when the page loads.
There was a problem hiding this comment.
The screenshot of GitHub is RIGHT because when a user clicks "Edit Profile", they ARE HIGHLY LIKELY going to edit their "display" name, and that focus helps to make the newly shown "edit profile form" focused. That's different from a NORMAL page.
But as I said above: Gitea's most "autofocus" usages are abuses.
Why you assume that when a user goes to the "settings profile" page, they are highly likely going to change their username?
|
I reverted all the other modifications and only kept the changes on the page shown in my screenshot. |
|
-> Fix autofocus behavior #34397 |



before:

after:
