mirror of
https://github.com/discourse/discourse.git
synced 2025-02-28 08:19:13 +00:00
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:
parent
78022e7a5f
commit
4bc769cac0
@ -3,6 +3,7 @@ import { disableImplicitInjections } from "discourse/lib/implicit-injections";
|
|||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
|
import { getOwner } from "@ember/application";
|
||||||
|
|
||||||
function pick(object, keys) {
|
function pick(object, keys) {
|
||||||
const result = {};
|
const result = {};
|
||||||
@ -28,6 +29,7 @@ export default class DModalBody extends Component {
|
|||||||
if (fixedParent) {
|
if (fixedParent) {
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
$(fixedParent).modal("show");
|
$(fixedParent).modal("show");
|
||||||
|
getOwner(this).lookup("controller:modal").hidden = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
this.modalClass
|
this.modalClass
|
||||||
this.modalStyle
|
this.modalStyle
|
||||||
(if this.hasPanels "has-panels")
|
(if this.hasPanels "has-panels")
|
||||||
|
(if @hidden "hidden")
|
||||||
}}
|
}}
|
||||||
id={{if (not-eq this.modalStyle "inline-modal") "discourse-modal"}}
|
id={{if (not-eq this.modalStyle "inline-modal") "discourse-modal"}}
|
||||||
data-keyboard="false"
|
data-keyboard="false"
|
||||||
|
@ -6,6 +6,7 @@ import { disableImplicitInjections } from "discourse/lib/implicit-injections";
|
|||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
|
import { getOwner } from "@ember/application";
|
||||||
|
|
||||||
@disableImplicitInjections
|
@disableImplicitInjections
|
||||||
export default class DModal extends Component {
|
export default class DModal extends Component {
|
||||||
@ -146,19 +147,21 @@ export default class DModal extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.fixed) {
|
if (data.fixed) {
|
||||||
this.wrapperElement.classList.remove("hidden");
|
getOwner(this).lookup("controller:modal").hidden = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.modalBodyData = data;
|
this.modalBodyData = data;
|
||||||
|
|
||||||
schedule("afterRender", () => {
|
next(() => {
|
||||||
this._trapTab();
|
schedule("afterRender", () => {
|
||||||
|
this._trapTab();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
_handleModalEvents(event) {
|
_handleModalEvents(event) {
|
||||||
if (this.wrapperElement.classList.contains("hidden")) {
|
if (this.args.hidden) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +180,7 @@ export default class DModal extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_trapTab(event) {
|
_trapTab(event) {
|
||||||
if (this.wrapperElement.classList.contains("hidden")) {
|
if (this.args.hidden) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@ import Component from "@ember/component";
|
|||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
$(".d-modal.fixed-modal").modal("hide").addClass("hidden");
|
$(".d-modal.fixed-modal").modal("hide");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
export default Controller.extend();
|
import { tracked } from "@glimmer/tracking";
|
||||||
|
|
||||||
|
export default class ModalController extends Controller {
|
||||||
|
@tracked hidden;
|
||||||
|
}
|
||||||
|
@ -190,6 +190,7 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
|
|||||||
}
|
}
|
||||||
modalController.set("name", null);
|
modalController.set("name", null);
|
||||||
}
|
}
|
||||||
|
modalController.hidden = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
@panels={{this.panels}}
|
@panels={{this.panels}}
|
||||||
@selectedPanel={{this.selectedPanel}}
|
@selectedPanel={{this.selectedPanel}}
|
||||||
@onSelectPanel={{this.onSelectPanel}}
|
@onSelectPanel={{this.onSelectPanel}}
|
||||||
@class="hidden"
|
@hidden={{this.hidden}}
|
||||||
@errors={{this.errors}}
|
@errors={{this.errors}}
|
||||||
@closeModal={{route-action "closeModal"}}
|
@closeModal={{route-action "closeModal"}}
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user