Skip to content
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

api.HTMLElement.focus - incompabile behaviour on input elements #25932

Open
aadcg opened this issue Feb 16, 2025 · 3 comments
Open

api.HTMLElement.focus - incompabile behaviour on input elements #25932

aadcg opened this issue Feb 16, 2025 · 3 comments
Labels
data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API p3 Low priority – Community PRs encouraged.

Comments

@aadcg
Copy link

aadcg commented Feb 16, 2025

What type of issue is this?

Browser bug (a bug with a feature that may impact site compatibility)

What information was incorrect, unhelpful, or incomplete?

I've noticed that on WebKitGTK calling focus also selects the value of input elements. On Firefox, you're required to call focus and select.

What browsers does this problem apply to, if applicable?

Safari

What did you expect to see?

As per the spec, it seems that focus shouldn't select.

Did you test this? If so, how?

Tested on WebKitGTK and Firefox.

<input id="myTextField" value="Text field." />
<button id="focusButton">Click to set focus on the text field</button>
document.getElementById("focusButton").addEventListener("click", () => {
  document.getElementById("myTextField").focus();
});

Can you link to any release notes, bugs, pull requests, or MDN pages related to this?

No response

Do you have anything more you want to share?

No response

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus

MDN metadata

MDN page report details
  • Query: api.HTMLElement.focus
  • Report started: 2025-02-16T17:49:19.301Z
@aadcg aadcg added the needs triage This issue needs to be confirmed label Feb 16, 2025
@github-actions github-actions bot added the data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API label Feb 16, 2025
@caugner
Copy link
Contributor

caugner commented Feb 18, 2025

This seems to have already been reported in the WebKit bug tracker: https://bugs.webkit.org/show_bug.cgi?id=56820

Verified with this MDN Playground.

The behavior might be caused by these lines in the WebKit source: https://github.com/WebKit/WebKit/blob/c638de65783f7bdc50e27c165eac138956d000d6/Source/WebCore/dom/Element.cpp#L4077-L4084

Note that the observed behavior is similar to tabbing into the input field, in which case all browsers seem to select the value.

@caugner
Copy link
Contributor

caugner commented Feb 18, 2025

For now, we could add a note on the Safari support statement for api.HTMLElement.focus:

On editable elements, the value is selected as a side-effect.

@caugner caugner added p3 Low priority – Community PRs encouraged. and removed needs triage This issue needs to be confirmed labels Feb 18, 2025
@aadcg
Copy link
Author

aadcg commented Feb 19, 2025

@caugner thanks for confirming and adding those pieces of information.

For now, we could add a note on the Safari support statement for api.HTMLElement.focus:

I have never contributed to MDN. Since this is a trivial change, I'd prefer if you'd went ahead and created a PR. Otherwise, I'd need to get acquainted with the project and the contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API p3 Low priority – Community PRs encouraged.
Projects
None yet
Development

No branches or pull requests

2 participants