Bug 224425 - setSelectionRange() on blur re-focuses input element
Summary: setSelectionRange() on blur re-focuses input element
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: Safari 14
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-12 02:12 PDT by Cetin Sert
Modified: 2021-04-13 01:49 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cetin Sert 2021-04-12 02:12:23 PDT
See https://stackoverflow.com/questions/67055218/set-input-caret-position-on-blur-in-safari-without-refocusing-input

This is unique to Safari.

Is it possible to match the behavior of other browsers?
Comment 1 Cetin Sert 2021-04-12 02:16:11 PDT
In https://stackoverflow.com/questions/67055218/set-input-caret-position-on-blur-in-safari-without-refocusing-input (link to minimal playground test)

Safari is the only browser where 'setSelectionRange' interferes with blur (focus loss/change)
  'setSelectionRange' traps the user into '#a' in Safari with no way out!
  'selectionStart > 0' that I have added helps one escape on second attempt.

Is it possible to make 'setSelectionRange' behave like other browsers i.e. not interrupt / mess with 'blur' / 'focus loss/change'.
Comment 2 Ryosuke Niwa 2021-04-12 23:24:17 PDT
This is behaving correctly. In WebKit, focus follows selection so if you modify selection, then the focus will be moved there.
Comment 3 Cetin Sert 2021-04-13 01:30:08 PDT
Mr. Niwa!

Thank you for your reply.

I have sent a pull request to Mozilla/PDF.js to switch from 'setSelectionRange(0, 0)' to 'scrollLeft = 0' and have long patched it in my own project. We can consider this issue resolved if WebKit project does not deem it necessary to match 'setSelectionRange(0, 0)' behavior with other browsers.
Comment 4 Cetin Sert 2021-04-13 01:31:01 PDT
See https://github.com/mozilla/pdf.js/pull/13232 for more details.
Comment 5 Ryosuke Niwa 2021-04-13 01:49:40 PDT
(In reply to Cetin Sert from comment #3)

> I have sent a pull request to Mozilla/PDF.js to switch from
> 'setSelectionRange(0, 0)' to 'scrollLeft = 0' and have long patched it in my
> own project. We can consider this issue resolved if WebKit project does not
> deem it necessary to match 'setSelectionRange(0, 0)' behavior with other
> browsers.

Yeah, I saw that :) Thanks for reporting the bug anyway.