document.onselectionchange does not detect changes on input/textarea
Categories
(Core :: DOM: Selection, defect)
Tracking
()
Tracking | Status | |
---|---|---|
firefox92 | --- | fixed |
People
(Reporter: saschanaz, Assigned: saschanaz)
References
()
Details
(Keywords: dev-doc-complete)
Attachments
(6 files)
- Open the attachment
- Click or type anywhere
Firefox: The listener on document
listens selection changes for text nodes inside <body>
, while listeners on each node listen the selection changes within them
Chrome: The listener on document
listens all events, while listeners on each node gets nothing.
Comment 1•4 years ago
|
||
Hi Kagami, I wonder what the spec says about the expected behavior here.
Assignee | ||
Comment 2•4 years ago
|
||
Selection API is the spec.
... the user agent must queue a task to fire an event with the name selectionchange, which does not bubble and is not cancelable, at the document associated with the selection.
So it should always go to document
per the spec. This behavior is defined back in 2014 and hasn't changed after that.
Updated•4 years ago
|
Assignee | ||
Comment 3•4 years ago
|
||
The relevant discussion: https://github.com/w3c/selection-api/issues/53
There has been no conclusion yet.
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Comment 4•4 years ago
|
||
Updated•4 years ago
|
Assignee | ||
Comment 5•4 years ago
|
||
Depends on D86700
Assignee | ||
Comment 6•4 years ago
|
||
Depends on D86701
Updated•4 years ago
|
Comment 7•4 years ago
|
||
There are some r+ patches which didn't land and no activity in this bug for 2 weeks.
:saschanaz, could you have a look please?
For more information, please visit auto_nag documentation.
Assignee | ||
Updated•4 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Assignee | ||
Updated•3 years ago
|
Updated•3 years ago
|
Assignee | ||
Comment 8•3 years ago
|
||
Depends on D86702
Assignee | ||
Comment 9•3 years ago
|
||
Depends on D118378
Comment 10•3 years ago
|
||
Comment 12•3 years ago
|
||
Backed out 5 changesets (bug 1648944) for causing wpt failures in idlharness.window.html.
https://hg.mozilla.org/integration/autoland/rev/d0153e71497bf81effe83239986d2a5f9c1edaf3
Push with failures:
https://treeherder.mozilla.org/jobs?repo=autoland&revision=598789cabb9f658e758194e925fe3bae7ebe144a&selectedTaskRun=I5vJOsQLTH66XyTAvNAWgg.0
Failure log:
https://treeherder.mozilla.org/logviewer?job_id=345724820&repo=autoland&lineNumber=2614
Assignee | ||
Updated•3 years ago
|
Comment 14•3 years ago
|
||
Comment 15•3 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/bc89ae91a71f
https://hg.mozilla.org/mozilla-central/rev/d6e87218e444
https://hg.mozilla.org/mozilla-central/rev/e2ae12fa4349
https://hg.mozilla.org/mozilla-central/rev/c1b4c369421b
https://hg.mozilla.org/mozilla-central/rev/02e7901e8253
Assignee | ||
Updated•3 years ago
|
Comment 17•3 years ago
|
||
I'm documenting this change for FF92, which you will be able to track here: https://github.com/mdn/content/issues/7755
As I understand the spec,
- the event
selectionchanged
will be fired on atextarea
orinput
if the selection changes. In this case the event will be fired on the selected element but propagates up to the global event handler GlobalEventHandlers.onselectionchange. It is cancellable and bubblable.
By selection changes in I mean specifically if you change the caret position (using mouse or by adding new characters) or the number of items selected. But just a focus change is not enough - if you switch back and forth to a text area without changing the caret you won't get the event. selectionchanged
will also be fired if you change a selected range outside of atextarea
orinput
. This might mean changing the focus or clicking pretty much anywhere outside the other two text field. In this case though the event is fired on theDocument
and is not cancelable and bubblable.
Is that about right?
To me that means that the docs changes are:
- We already have Document: selectionchange_event but we need to create
text_input
: selectionchange_eventand
input: selectionchange_event` - We already have a
GlobalEventHandlers.onselectionchange
handler- docs says the captured event is a
FocusEvent
. Shouldn't this be a selected_change event? - The example just uses
document.getSelection()
. Is that sufficient? Should we be encouraging the user to be looking at the selection and/or event to determine what has been selected?
- docs says the captured event is a
- The changes in this fix also look like they make Firefox compliant with this spec. Do you think it makes sense to add a note to the browser compatibility that this has been fixed in FF92? Something like "Version 92 fixes a bug where selection events were not fired from
textarea
orinput
elements?
Assignee | ||
Comment 18•3 years ago
|
||
(In reply to Hamish Willee from comment #17)
I'm documenting this change for FF92, which you will be able to track here: https://github.com/mdn/content/issues/7755
As I understand the spec,
- the event
selectionchanged
will be fired on atextarea
orinput
if the selection changes. In this case the event will be fired on the selected element but propagates up to the global event handler GlobalEventHandlers.onselectionchange. It is cancellable and bubblable.
By selection changes in I mean specifically if you change the caret position (using mouse or by adding new characters) or the number of items selected. But just a focus change is not enough - if you switch back and forth to a text area without changing the caret you won't get the event.selectionchanged
will also be fired if you change a selected range outside of atextarea
orinput
. This might mean changing the focus or clicking pretty much anywhere outside the other two text field. In this case though the event is fired on theDocument
and is not cancelable and bubblable.Is that about right?
- "selectionchange".
- It's never cancelable, but does bubble when it's from textarea or input.
- Focusing textarea/input shouldn't fire the event, right.
- Clicking generally changes selection and thus should fire the event outside of textarea/input, yes. Focusing doesn't always change selection, though. (Right-clicking a link sets the focus (
document.activeElement
) but does not change the selection (getSelection().focusNode
).)
To me that means that the docs changes are:
- We already have Document: selectionchange_event but we need to create
text_input
: selectionchange_eventand
input: selectionchange_event`- We already have a
GlobalEventHandlers.onselectionchange
handler
- docs says the captured event is a
FocusEvent
. Shouldn't this be a selected_change event?- The example just uses
document.getSelection()
. Is that sufficient? Should we be encouraging the user to be looking at the selection and/or event to determine what has been selected?- The changes in this fix also look like they make Firefox compliant with this spec. Do you think it makes sense to add a note to the browser compatibility that this has been fixed in FF92? Something like "Version 92 fixes a bug where selection events were not fired from
textarea
orinput
elements?
FocusEvent
is wrong indeed, it should just beEvent
.document.getSelection()
is indeed not helpful in textarea/input case sincegetSelection()
says nothing about their selection. It should rather usetextarea.selectionStart
etc.- I'd say it's a feature rather than a bug, since it's a recent change to allow the event from textarea/input: https://github.com/w3c/selection-api/pull/141
Comment 19•3 years ago
|
||
Thanks very much! FYI
- I have created new docs for the
selectionchange
events fired byHTMLInputElement
andHTMLTextAreaElement
in https://github.com/mdn/content/pull/8222 (and updatesonselectionchanged
) to note it can get events from both sources. - Release note updated in https://github.com/mdn/content/pull/8248
- BCD is "under discussion" in https://github.com/mdn/browser-compat-data/pull/12126 (I am still not sure if I need to update
onselectionchanged
as well as adding the new events.
Review welcomed.
Description
•