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

Conversation

kerwin612
Copy link
Member

before:
before

after:
after

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 21, 2025
@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Apr 21, 2025
@wxiaoguang
Copy link
Contributor

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.

@kerwin612
Copy link
Member Author

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:
① First of all, when there are input elements on the page, the user experience will be better if the first input element can be automatically focused on.
② Secondly, when the value of the input element is not empty, the user experience will also be better if the cursor is automatically focused after the last character.
I believe that a good user experience can only be achieved when both of the above points are met. If we simply focus without considering the situation where the value is not empty, it will lead to a poor user experience.

As I'm writing this, I'm thinking about whether we can add a utility function in the Go code:

  • Go
func inputAttrs(value string) string {
    if value != "" {
        return "data-global-init=\"initInputAutoFocusEnd\""
    }
    return "autofocus"
}
  • Template
<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.

@wxiaoguang
Copy link
Contributor

① First of all, when there are input elements on the page, the user experience will be better if the first input element can be automatically focused on.

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
Copy link
Contributor

Don't you see some changes are wrong?

image

What's the difference between normal auto-focus and focus-cursor-end for URL and Token inputs? Why end users would to "append" anything to that inputs?

image

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

Don't make changes which you don't understand.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 22, 2025
@kerwin612
Copy link
Member Author

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.

Yes, so my view is that if the autofocus is unnecessary, we should remove it. If autofocus is necessary, I suggest we optimize it properly, just as per the solution I mentioned above.

@kerwin612 kerwin612 force-pushed the feat/replace-autofocus branch from 159ebec to c0f8c62 Compare April 22, 2025 00:36
@@ -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?

@kerwin612
Copy link
Member Author

I reverted all the other modifications and only kept the changes on the page shown in my screenshot.

@wxiaoguang wxiaoguang marked this pull request as draft April 24, 2025 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged modifies/templates This PR modifies the template files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants