DEV: Control modal 'hidden' with Ember (#21562)

Moving all control of 'hidden' into Ember will resolve issues we're seeing with Ember fighting against manual DOM manipulation (both vanilla JS and JQuery).

Looking up `controller:modal` from components is not ideal. However, the next step in the refactoring is to create a modal 'service' which will be able to injected into components cleanly.
This commit is contained in:
David Taylor 2023-05-15 20:48:00 +01:00 committed by GitHub
parent 78022e7a5f
commit 4bc769cac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import { disableImplicitInjections } from "discourse/lib/implicit-injections";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { inject as service } from "@ember/service";
import { getOwner } from "@ember/application";
function pick(object, keys) {
const result = {};
@ -28,6 +29,7 @@ export default class DModalBody extends Component {
if (fixedParent) {
this.fixed = true;
$(fixedParent).modal("show");
getOwner(this).lookup("controller:modal").hidden = false;
}
this.appEvents.trigger(

View File

@ -8,6 +8,7 @@
this.modalClass
this.modalStyle
(if this.hasPanels "has-panels")
(if @hidden "hidden")
}}
id={{if (not-eq this.modalStyle "inline-modal") "discourse-modal"}}
data-keyboard="false"

View File

@ -6,6 +6,7 @@ import { disableImplicitInjections } from "discourse/lib/implicit-injections";
import { inject as service } from "@ember/service";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { getOwner } from "@ember/application";
@disableImplicitInjections
export default class DModal extends Component {
@ -146,19 +147,21 @@ export default class DModal extends Component {
}
if (data.fixed) {
this.wrapperElement.classList.remove("hidden");
getOwner(this).lookup("controller:modal").hidden = false;
}
this.modalBodyData = data;
schedule("afterRender", () => {
this._trapTab();
next(() => {
schedule("afterRender", () => {
this._trapTab();
});
});
}
@bind
_handleModalEvents(event) {
if (this.wrapperElement.classList.contains("hidden")) {
if (this.args.hidden) {
return;
}
@ -177,7 +180,7 @@ export default class DModal extends Component {
}
_trapTab(event) {
if (this.wrapperElement.classList.contains("hidden")) {
if (this.args.hidden) {
return true;
}

View File

@ -2,6 +2,6 @@ import Component from "@ember/component";
export default Component.extend({
didInsertElement() {
this._super(...arguments);
$(".d-modal.fixed-modal").modal("hide").addClass("hidden");
$(".d-modal.fixed-modal").modal("hide");
},
});

View File

@ -1,2 +1,6 @@
import Controller from "@ember/controller";
export default Controller.extend();
import { tracked } from "@glimmer/tracking";
export default class ModalController extends Controller {
@tracked hidden;
}

View File

@ -190,6 +190,7 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
}
modalController.set("name", null);
}
modalController.hidden = true;
},
/**

View File

@ -6,7 +6,7 @@
@panels={{this.panels}}
@selectedPanel={{this.selectedPanel}}
@onSelectPanel={{this.onSelectPanel}}
@class="hidden"
@hidden={{this.hidden}}
@errors={{this.errors}}
@closeModal={{route-action "closeModal"}}
>