mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 14:53:30 +00:00
Add confirmation dialog before closing host lobby modal 🔧 (#3364)
## Description: Show a confirm prompt when the user tries to close the host lobby via click-outside or Escape key, preventing accidental lobby exits. Happened to many people and also DougDoug... Does not show the prompt when the user clicks the arrow button because it's probably intentional. ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin
This commit is contained in:
@@ -39,6 +39,11 @@ export abstract class BaseModal extends LitElement {
|
||||
if (this.modalEl) {
|
||||
this.modalEl.onClose = () => {
|
||||
if (this.isModalOpen) {
|
||||
if (!this.confirmBeforeClose()) {
|
||||
// Re-open the underlying o-modal since it already closed itself
|
||||
this.modalEl?.open();
|
||||
return;
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
@@ -57,6 +62,9 @@ export abstract class BaseModal extends LitElement {
|
||||
private handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && this.isModalOpen) {
|
||||
e.preventDefault();
|
||||
if (!this.confirmBeforeClose()) {
|
||||
return;
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
@@ -93,6 +101,15 @@ export abstract class BaseModal extends LitElement {
|
||||
// Default implementation does nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Guard called before closing via Escape key or click-outside.
|
||||
* Override in subclasses to show a confirmation dialog.
|
||||
* Return false to prevent the modal from closing.
|
||||
*/
|
||||
public confirmBeforeClose(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the modal. Handles both inline and modal element modes.
|
||||
* Subclasses can override onOpen() for custom behavior.
|
||||
|
||||
Reference in New Issue
Block a user