Documentation concerning the select event on textarea and input elements

I have a question about this document On select Event.

Is there any documentation on which user actions trigger the event? In attempting to use this event along with the inputType property of the input event, I noticed that, at least on a regular keyboard and a desktop computer running Windows 10, there are actions that select the text in a textarea that do not result in the select event being fired/triggered.

For example, although the browser makes a selection within the textarea, the select event is not fired on the textarea when hold Shift (or Shift and Control ) and press PageUp or PageDown; or when hold Shift and Control and press Home or End. It does however fire for Shift + Home and Shfit + End, just not when Control is pressed also.

Perhaps I am misunderstanding or doing something incorrectly, or this is old news of which I’m just becoming aware.

Thank you for any direction you may be able to provide.

Hi @codedebugger! This is a really interesting question. I’ve just done some testing on macOS, and the “regular” ways of selecting text seems to trigger the event (mouse, keyboard combinations such as Cmd + A, and Shift plus the cursor keys).

But Shift/Shift + Ctrl plus PgUp/PgDown don’t work on Firefox. And only Shift plus PgUp/PgDown works on Chrome.

It would be interesting to do some more testing and add the results to the page. I don’t know of such a list anywhere.

Thank you for replying and checking on Mac.

Using the setRangeText method triggers the select event also, in Firefox at least.

I don’t know enough about how browsers are coded to know at what point a select event notification is sent out, but it seems odd that it would be tied to user action separate from the operation that does the selecting on the screen. One would imagine that immediately after the selection is made, regardless of what triggered the browser to make the selection, the notification would be sent.

I suppose a list would include all the ways a user or coder can employ to select text in the browser and which of those fire the select event. Then the question would be why isn’t the select event fired in all cases.

I’ve been capturing the selection and/or its range onselect because most of the inputType events notfiy after the fact, such as after the selection has alredy been deleted or replaced, and there doesn’t appear to be a beforeinput event in Firefox. The keydown event catches the key strokes that don’t fire the select event, of course, but the selection detail cannot be captured until after keyup.

Thanks.

I wish I had more answers here, as to why things work as they do. The more you look, the more you find strange things like this :wink:

I think the information would still be useful, even if does beg the question of why it isn’t fired in all cases.

Oh, and FYI — Firefox does have the beforeinput event; it just isn’t enabled by default yet. I’m not sure what the schedule is for enabling that; we’ve had it since Fx 74.

I agree that it would be useful information. It certainly would’ve been helpful to me a couple days ago. I read a book a few years ago on farming and the author wrote in the preface something along the lines of “this little book of mine isn’t anything especially great or profound, but I sure wish I has a copy of it twenty-five years ago when I first started farming.” When you don’t know, a list like you mentioned can be very helpful.

When I searched the first time, all I could find on beforeinput was this MDN Document which doesn’t mention anything about the event being available based on a preference setting, and I read an older post that stated Firefox doesn’t support it; but, after reading your last comment, I searched again and found this bugzilla exchange, closed five months ago, which does mention that.

Is it your understanding then that beforeinput works now in Firefox if the dom.input_events.beforeinput.enabled preference is set to true? Of course, I can just try it out, but I mean should it work as it will whenever they decide to make it the default.

I have a little trouble following the bugzilla exchange to understand what the conclusion was.

Thank you.