Skip to content

Replace autofocus with data-global-init="initInputAutoFocusEnd". #34252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/user/settings/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<span class="text red tw-hidden" id="name-change-prompt"> {{ctx.Locale.Tr "settings.change_username_prompt"}}</span>
<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">
Copy link
Contributor

@wxiaoguang wxiaoguang Apr 22, 2025

Choose a reason for hiding this comment

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

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

after

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. It is NOT username
  2. It is NOT autofocus or initInputAutoFocusEnd. They WILL NOT WORK because the element is hidden when the page loads.

Copy link
Contributor

@wxiaoguang wxiaoguang Apr 22, 2025

Choose a reason for hiding this comment

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

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?

{{if or (not .SignedUser.IsLocal) ($.UserDisabledFeatures.Contains "change_username") .IsReverseProxy}}
<p class="help text blue">{{ctx.Locale.Tr "settings.password_username_disabled"}}</p>
{{end}}
Expand Down