Skip to content
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

Revert "Fix dialogs rendered inside menu items" #2467

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .changeset/breezy-weeks-explode.md

This file was deleted.

33 changes: 4 additions & 29 deletions app/components/primer/alpha/action_menu/action_menu_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class ActionMenuElement extends HTMLElement {
const dialog = this.ownerDocument.getElementById(dialogInvoker.getAttribute('data-show-dialog-id') || '')

if (dialog && this.contains(dialogInvoker) && this.contains(dialog)) {
this.#handleDialogItemActivated(event, dialog as HTMLDialogElement)
this.#handleDialogItemActivated(event, dialog)
return
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ export class ActionMenuElement extends HTMLElement {
}
}

#handleDialogItemActivated(event: Event, dialog: HTMLDialogElement) {
#handleDialogItemActivated(event: Event, dialog: HTMLElement) {
this.querySelector<HTMLElement>('.ActionListWrap')!.style.display = 'none'
const dialog_controller = new AbortController()
const {signal} = dialog_controller
Expand All @@ -286,33 +286,8 @@ export class ActionMenuElement extends HTMLElement {
setTimeout(() => this.invokerElement?.focus(), 0)
}
}

// At this point, the dialog is about to open. When it opens, all other popovers (incuding
// this ActionMenu) will be closed. We listen to the toggle event here, which will fire when
// the menu is closed and manually re-open it. When the menu is re-opened, it gets added to
// the top of the popover stack. Only the item at the top of the stack will close when the
// escape key is pressed, so we add another beforetoggle listener. When the escape key is
// pressed, the listener is invoked, which manually closes the dialog. Closing the dialog
// causes the dialog's close event to fire, which
this.popoverElement?.addEventListener(
'toggle',
(toggleEvent: Event) => {
if ((toggleEvent as ToggleEvent).newState === 'closed') {
this.#show()
this.popoverElement?.addEventListener(
'beforetoggle',
(beforeToggleEvent: Event) => {
if ((beforeToggleEvent as ToggleEvent).newState === 'closed') {
dialog.close()
}
},
{signal},
)
}
},
{signal, once: true},
)

// a modal <dialog> element will close all popovers
setTimeout(() => this.#show(), 0)
dialog.addEventListener('close', handleDialogClose, {signal})
dialog.addEventListener('cancel', handleDialogClose, {signal})
}
Expand Down
Loading