-
Notifications
You must be signed in to change notification settings - Fork 7
Add Menu target click()
support
#986
Conversation
🦋 Changeset detectedLatest commit: 0f716fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
95e0a8f
to
b6c90cc
Compare
// `true` in the consumer's handler isn't overwritten by `#onDocumentClick()` | ||
// handler setting it to `false`. | ||
document.addEventListener('click', this.#onDocumentClick, { | ||
capture: true, |
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 calling click()
on sub-Menu targets wasn't supported was because this listener listened for "click" in its capture phase, and this.#onDocumentClick()
closes Menu when a click doesn't come from Menu.
Because it listened in the capture phase, we had to rely on #onTargetSlotMouseUp()
(which is called before "click" is dispatched) to determine in this.#onDocumentClick()
if the click came from a Menu target. And "mouseup" events, of course, aren't dispatched for programmatic clicks. So we had no way to set this.#isTargetSlotMouseUp
when a target was clicked via click()
.
Now that this.#onDocumentClick()
is called in the bubble phase, we can ditch this.#isTargetSlotMouseUp
and #onTargetSlotMouseUp()
, and simply set this.#isTargetSlotClick
in #onTargetSlotClick()
. After #onTargetSlotClick()
is called, the event bubbles up to this.#onDocumentClick()
.
b6c90cc
to
e359869
Compare
}); | ||
|
||
// See the comment in `connectedCallback()` for an explanation. | ||
it('opens when opened programmatically via the click handler of another element', async () => { |
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.
Menu can no longer be opened by setting its
open
attribute via the "click" handler of an element outside Menu. If you need to open Menu via the "click" handler of an element outside Menu, you can callclick()
on Menu's target. This change was made to support opening sub-Menu targets programmatically viaclick()
.
e359869
to
1a5464a
Compare
// `sendMouse()` is just a thin abstraction over Playwright's equivalent API. So | ||
// the ultimate cause is likely Playwright or Chromium's DevTools Protocol, which | ||
// Playwright relies on. Either that or I'm missing something obvious. | ||
targets[1]?.click(); |
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.
As a bonus, we can now call click()
in tests—which I believe will resolve most if not all of the flakiness we've seen.
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.
That said, there still appears to be systemic issues causing sporadic flakiness of various tests, and we've been seeing for some time. The cause isn't clear to me.
I had hoped that Playwright's support for component testing would be stable by now. When it finally is (and when they support web components with it), we'll move to it and hopefully things will stabilize. Until then, there are a couple things we can try:
- Chromium's new headless mode.
- Break our tests out into smaller suites.
Chromium's new headless mode isn't quite there yet in terms of quality. Either that or it doesn't work well with Web Test Runner. But we can break out the tests out now—which probably isn't a bad idea anyway because doing so could cut our build times in half. So I'll do that soon.
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.
Thanks!
1a5464a
to
2121032
Compare
|
||
Menu can no longer be opened by setting its `open` attribute via the "click" handler of an element outside Menu. | ||
If you need to open this way, you can call `click()` on Menu's target in your handler. | ||
This change was made to support the ability to open sub-Menu targets programmatically by calling `click()`. |
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.
It was nice to be able to support setting open
this way. But supporting it precluded consumers being able to call click()
on sub-Menu targets.
And there's an alternative. But there's no alternative to not being able to call click()
on a sub-Menu target. So, overall, a net improvement for consumers.
c7ac011
to
1aa2cf1
Compare
1aa2cf1
to
54d363d
Compare
expect(tooltips[2]?.open).to.be.true; | ||
expect(tooltips[3]?.open).to.be.true; | ||
expect(tooltips[4]?.open).to.be.false; | ||
expect(tooltips[5]?.open).to.be.false; |
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.
Flaky and nice but not necessary to assert in this test.
// `sendMouse()` is just a thin abstraction over Playwright's equivalent API. So | ||
// the ultimate cause is likely Playwright or Chromium's DevTools Protocol, which | ||
// Playwright relies on. Either that or I'm missing something obvious. | ||
targets[1]?.click(); |
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.
Thanks!
Co-authored-by: Tony Ward <8069555+ynotdraw@users.noreply.github.com>
🚀 Description
📋 Checklist
🔬 Testing
Sub-Menus of Menu can now be opened by programmatically calling
click()
on sub-Menu targetsclick()
on the top-level Menu's target.click()
on the sub-Menu's target.click()
on the sub-Menu's target.