Repository navigation
Description
I came across this issue while re-triaging this chrome bug.
When clicking an element inside a disabled button element, chrome firefox and safari all don't dispatch click events on the disabled form element itself. However, chrome and safari both allow the click event to keep bubbling up the dom, whereas firefox stops the bubbling after the disabled button:
<div id=parent>
<button disabled>
<span id=child>click me</span>
</button>
</div>| chrome | safari | firefox | |
|---|---|---|---|
| #parent | click | click | none |
| button | none | none | none |
| #child | click | click | click |
In the case that there is no element inside the button, there is no bubbling that occurs in any of the browsers:
<div id=parent>
<button disabled>click me</button>
</div>| chrome | safari | firefox | |
|---|---|---|---|
| #parent | none | none | none |
| button | none | none | none |
Considering that in the case where there is no element inside the button the bubbling stops, I think that we should probably follow the firefox behavior - why should adding an element inside the button change what events the parent elements of the dom see...?
The spec says that "A form control that is disabled must prevent any click events that are queued on the user interaction task source from being dispatched on the element."
The chrome implementation of this just checks if the target element is a disabled form control before dispatching events on any element in general inside the event dispatcher, which more or less seems to follow the wording of the spec since it doesn't say anything about stopping the bubbling.
Should I change the chrome behavior to be like firefox?
Should we change what the spec says? If so, what should it say?
Some posts I found about this behavior by searching:
Activity
domenic commentedon Sep 2, 2020
It'd be good to solve this in tandem with #2368. It looks like there @rniwa was in agreement with you that the Firefox behavior is better.
It seems like the proposal is to truncate the event path for all mouse events (and pointer events?) to remove disabled form controls, and any of their (shadow-including??) parents.
@annevk, can you think of any way to spec this without modifying event dispatch?
The current spec seems to be advocating for a third behavior, which is to don't dispatch the event when the target would be a disabled form control. This would result in clicking on children of a disabled button firing the event, but in that case the event should reach the disabled form control (since dispatch was not prevented). And no browsers seem to follow that.
The current spec is nice and simple and does not need to get into the innards of event dispatch; it just serves as input into the question of whether or not to dispatch. But, it's probably not good for web developers, and it's not what anyone implements, so oh well.
josepharhar commentedon Sep 3, 2020
Thanks, I didn't know about #2368, it sounds like it has the same root cause as this bug.
I found the SendMouseEventsDisabledFormControls flag in chrome, and I found that it has behavior different from what I've documented so far. I also looked and .click() and physical clicks separately:
@dtapuska it looks like you added the flag, what are your thoughts on this behavior? Do you think this flag will become enabled by default?
annevk commentedon Sep 7, 2020
See whatwg/dom#687. It seems that a custom get the parent for elements might be a way of achieving this, but we should probably first sort out where we want everyone to end up.
pruthvi3007 commentedon Oct 3, 2020
mercmobily commentedon Mar 2, 2022
Sorry about the noise... I was just wondering if there was progress in this; it affects my code -- I have workaround code, and I would like to figure out when to task the deletion of the workaround. Thanks!
josepharhar commentedon Jun 24, 2022
I believe that the stable chrome and safari behavior is best here. I'll try to make sure that experimental chrome doesn't have the weird behavior where none of the event handlers are fired.
I think that web-platform-tests/wpt#32381 includes tests for this behavior.
cc @saschanaz
smaug---- commentedon Jun 28, 2022
What is stable Chrome behavior? Propagating click from child elements of a disable button to the ancestor of the button, but not firing on the button itself. That is just weird. I'm rather strongly against such behavior. I don't think we have other cases where we drop magically an item from the event path. (But I could add that implementing Chrome's behavior in Gecko should be very easy, one would just change the parent target, if the default parent was disabled)
mercmobily commentedon Jun 28, 2022
I couldn't possibly agree more.
jakearchibald commentedon Jun 28, 2022
Agreed.
It seems reasonable to not-dispatch a click event if it's performed on a disabled button. "click" is pretty much an activation event, but a disabled button cannot be activated.
Dispatching "click" but skipping the button in the event path is weird.
saschanaz commentedon Jun 28, 2022
Should we dupe this to #2368?
I totally agree that it's weird, but Mozilla has received multiple webcompat reports (see https://bugzilla.mozilla.org/show_bug.cgi?id=1653882). Basically websites are trying to observe click events for disabled form elements by observing from their parent elements. One of the examples:
I think it is indeed too late. 😞
Edit: See also web-platform-tests/interop#27.
smaug---- commentedon Jun 28, 2022
Have other browsers gotten bug reports about the behavior they have?
76 remaining items
josepharhar commentedon Sep 4, 2023
Another regression bug was filed: https://bugs.chromium.org/p/chromium/issues/detail?id=1477379
The breakage so far all looks like websites which wouldn't have worked properly on firefox in the first place, since firefox has never fired click events on disabled
<input type=text>s or<textarea>s.KajSzy commentedon Sep 5, 2023
This chrome updated did scare me a lot.
I just realized that such structure will not fire any
onClickevent.The easiest solution was to change it to
onPointerUpSo after workaround
saschanaz commentedon Sep 18, 2023
I'll try shipping this on Firefox beta. If we get enough frustration reports then maybe we could discuss whether we can disable click only for button-like elements (including checkboxes and radio buttons) as blocking click makes best sense there and less for others.
Bug 1853941 - Enable dom.forms.always_allow_pointer_events / fieldset…
Bug 1853941 - Enable dom.forms.always_allow_pointer_events / fieldset…
Bug 1853941 - Enable dom.forms.always_allow_pointer_events / fieldset…
Bug 1853941 - Enable dom.forms.always_allow_pointer_events / fieldset…
Bug 1853941 - Enable dom.forms.always_allow_pointer_events / fieldset…
seal7766 commentedon Apr 22, 2024
@KajSzy
answer helped me.
However, the event occurs, but the state does not change when disabled due to React event delegation. I use the code below to circumvent this. I hope my answer helps others who have this problem.
Bug 1796696 [wpt PR 36578] - Stop click/mouseup/mousedown propagation…
Expand disabled form control event handling spec text
Expand disabled form control event handling spec text
Expand disabled form control event handling spec text
Make fieldset match :enabled and :disabled again
fix(webapi): trusted mouse events on a child of a disabled control st…