-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Ignore DOM state when hiding popovers if needed #9457
base: main
Are you sure you want to change the base?
Conversation
Fixes whatwg#9161 Fixes whatwg#9367 Makes obsolete whatwg/dom#1185 This PR prevents the hide popover algorithm from returning early when the popover attribute is removed or when the element with the popover attribute is removed from the document. The fireEvents parameter is used as an indicator that either the element is being removed or that the attribute is being removed, and when it is false, the calls to check popover validity are replaced with a check to simply see if the popover is already hidden. This patch also makes removal of the popover attribute stop firing events in order to signal to the hide popover algorithm that checks for the popover attribute should be ignored.
If anyone thinks that we should continue firing events when script runs |
It would increase inconsistency of the Popover API's behavior. Including making the (non-normative) description of the "beforetoggle" event (https://html.spec.whatwg.org/#event-beforetoggle) less precise. |
So do you think that if we continue firing events during |
Sorry for the unclarity. Events should continued to be fired during |
No strong opinion. While synchronous events around node tree mutations make me a bit nervous, they are "safe" for attributes as far as I know. |
Ok, I added parameters to check popover validity and hide popover in order to make removeAttribute('popover') start firing events again |
@@ -82411,7 +82412,7 @@ dictionary <dfn dictionary>DragEventInit</dfn> : <span>MouseEventInit</span> { | |||
|
|||
<li><p>If <var>oldValue</var> and <var>value</var> are in different <span | |||
data-x="attr-popover">states</span>, then run the <span>hide popover algorithm</span> given | |||
<var>element</var>, true, true, and false.</p></li> | |||
<var>element</var>, true, true, false, and true.</p></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implies https://whatpr.org/html/9457/8430871...acbbfdb/popover.html#check-popover-validity will skip checking whether the popover attribute is in the "no popover" state. However, value
can represent "auto" or "manual" and then the popover attribute should also correspond to it and hence should be checked, or?
Please be aware of the last paragraph of #9459 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change in #9526 this should be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change in #9526 this should be fine
Depends on what "fine" means. That check should still pass, e.g. when the popover is open and the attribute state changes from "auto" to "manual" but with this patch the check wouldn't be executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason that I added this here is because I want to make sure that the popover gets hidden even if the attribute is in the no popover state, so that the popover gets hidden when you call element.removeAttribute('popover')
.
However, value can represent "auto" or "manual" and then the popover attribute should also correspond to it and hence should be checked, or?
I suppose that we could pass false instead of true for ignoreDomState in the case that the new state is popover=auto or popover=manual, but what difference would it make? We still want to close the popover in these cases
but with this patch the check wouldn't be executed
You're talking about the check to see whether we are in the no popover state, right? In these cases we know that we are not in the no popover state already...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that we could pass false instead of true for ignoreDomState in the case that the new state is popover=auto or popover=manual, but what difference would it make?
It'd make the spec, and implementations, more robust. Otherwise, the latter's behaviors may differ, depending on their internals.
We still want to close the popover in these cases
Yes.
but with this patch the check wouldn't be executed
You're talking about the check to see whether we are in the no popover state, right?
Yes.
In these cases we know that we are not in the no popover state already...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend prototyping/implementing this in Firefox/Gecko, but it will take some time due to days off.
In case of attribute removal, it might make sense to not fire "beforetoggle" events, but only "toggle" events. This is motivated by the use case described at https://open-ui.org/components/popover.research.explainer/#events (updating server data). It might not matter, in which of those two events the server data is updated. This differs from a "beforetoggle" event when showing a popover, for which https://open-ui.org/components/popover.research.explainer/#events describes a use case. @domenic are you, as a contributor to https://open-ui.org/components/popover.research.explainer/, aware of other use cases or can please recommend any other contributor to shed light on this? |
Additionally, renaming "toggle" to "aftertoggle" seems more precise too. |
I'd prefer not to make these breaking changes to popover now that it has already shipped in stable chrome. I'm sure that some people like having a synchronous beforetoggle event when popovers close even if it isn't cancelable. If I remember correctly, we used the name "toggle" to match the existing toggle event for details elements. |
For context, here are some issues with discussions and resolutions about having both sync beforetoggle and async toggle events: openui/open-ui#342 openui/open-ui#578 |
Thanks. Wasn't aware of those tickets. openui/open-ui#342 states that "beforetoggle" is acceptable but not necessary when hiding a popover. Didn't fully read openui/open-ui#578 yet. |
Understandable, but that shouldn't be a stopper. If it's changed, the earlier, the painless.
If there was evidence about it, that'd be an argument.
Okay. Seems okay to keep the current name. |
I think that consistently firing both events instead of sometimes firing one and sometimes firing both is a more consistent behavior that will make it easier for developers to rely on. |
One issue with firing a "beforetoggle" event in the hide popover algorithm is, when |
It would be helpful to have use-cases for the "beforetoggle" event in case a popover is hidden. The feature has only recently shipped in Chrome stable and not in other browsers yet, according to https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/popover#browser_compatibility. |
@mfreed7 do you have any opinions about removing beforetoggle events during attribute removal or node removal? |
Sorry, I'm not sure what the question is, exactly. I don't think there are any "good" use cases for needing the |
Fixes #9161
Fixes #9367
Makes obsolete whatwg/dom#1185
This PR prevents the hide popover algorithm from returning early when the popover attribute is removed or when the element with the popover attribute is removed from the document.
The fireEvents parameter is used as an indicator that either the element is being removed or that the attribute is being removed, and when it is false, the calls to check popover validity are replaced with a check to simply see if the popover is already hidden.
This patch also makes removal of the popover attribute stop firing events in order to signal to the hide popover algorithm that checks for the popover attribute should be ignored.
(See WHATWG Working Mode: Changes for more details.)
/infrastructure.html ( diff )
/popover.html ( diff )