Fix premature close with content placed over trigger #1335
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issues
Background
Using a value of
mousedown
for theeventType
that is set on the Ember Basic Dropdown trigger is problematic in some cases, especially when content overlaps the trigger. The reason for this is that the subsequentmouseup
event handler that is set in theaddHandlers
action in theoptions.ts
file is triggered immediately after themousedown
that opens the dropdown content in the first place. Themouseup
event handler callsfindOptionAndPerform
which will select any valid, (though in this case accidentally) highlighted option and then immediate close the dropdown when it makes the selection.Note that even if the above
mouseup
event listener is bypassed, Ember Basic Dropdown will still immediately close the dropdown, though this time without Power Select having made a selection. This happens because, in thebasic-dropdown-content.ts
file, in thesetup
action adds aclick
event listener (based on the value ofthis.args.rootEventType
) to the document, to ensure the content is closed when the user clicks away from the menu.... but when the resultinghandleRootMouseDown
function is called theclick
event target isbody
, which signals EBD to close the content. It's not clear to me why thetarget
isbody
in this function, but I suspect it may be related to themousedown
andmouseup
targets differing here, when the content appears above the trigger.Specifying
@eventType='click'
instead bypasses both problems becauseclick
is fired only after themousedown
andmouseup
events, resulting in more predictable behavior, regardless of location of the content in relation to the trigger.Other Notes
Related, alternative PR