Skip to content

Commit 58b24c3

Browse files
committed
Improved modal docs
1 parent 4ee15fc commit 58b24c3

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

components/modal/modal.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class SuiModalService {
2525
$implicit: modal.context,
2626
// `let-modal="modal"`
2727
modal: componentRef.instance.controls
28-
});
28+
})
2929
}
3030
// If the config is for a component based modal,
3131
else if (modal instanceof ComponentModalConfig) {
@@ -59,6 +59,10 @@ export class SuiModalService {
5959
contentElement.remove();
6060
}
6161

62+
// Remove the template div from the DOM. This is to fix some styling issues.
63+
const templateElement = modalComponent.templateSibling.element.nativeElement as Element;
64+
templateElement.remove();
65+
6266
// Attach the new modal component to the application.
6367
this._applicationRef.attachView(componentRef.hostView);
6468

demo/src/app/pages/modal/modal.page.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const exampleTemplateModalTemplate = `
1212
<p>{{ context.data }}</p>
1313
</div>
1414
<div class="actions">
15-
<button class="ui red button" (click)="modal.deny('denied!')">Cancel</button>
16-
<button class="ui green button" (click)="modal.approve('approved!')">OK</button>
15+
<button class="ui red button" (click)="modal.deny('denied')">Cancel</button>
16+
<button class="ui green button" (click)="modal.approve('approved')">OK</button>
1717
</div>
1818
</ng-template>
1919
`;
@@ -153,7 +153,7 @@ export class MyComponent {
153153
public open(dynamicContent:string = "Example") {
154154
const config = new TemplateModalConfig<IContext, string, string>(this.modalTemplate);
155155
156-
config.isClosable = false;
156+
config.closeResult = "closed!";
157157
config.context = { data: dynamicContent };
158158
159159
this.modalService
@@ -195,8 +195,8 @@ export class ConfirmModal extends ComponentModalConfig<IConfirmModalContext, voi
195195
public componentOpen = `
196196
this.modalService
197197
.open(new ConfirmModal("Are you sure?", "Are you sure about accepting this?"))
198-
.onApprove(() => alert("accepted!"))
199-
.onDeny(() => alert("denied!"));
198+
.onApprove(() => alert("User has accepted."))
199+
.onDeny(() => alert("User has denied."));
200200
`;
201201
}
202202

@@ -215,13 +215,13 @@ export class ModalExampleTemplate {
215215
public open(dynamicContent:string = "Example") {
216216
const config = new TemplateModalConfig<{ data:string }, string, string>(this.modalTemplate);
217217

218-
config.isClosable = false;
218+
config.closeResult = "dismissed";
219219
config.context = { data: dynamicContent };
220220

221221
this.modalService
222222
.open(config)
223-
.onApprove(r => alert(r))
224-
.onDeny(r => alert(r));
223+
.onApprove(r => alert(`Accepted with result: '${r}'.`))
224+
.onDeny(r => alert(`Denied with result: '${r}'.`));
225225
}
226226
}
227227

@@ -258,8 +258,8 @@ export class ModalExampleComponent {
258258
public open() {
259259
this.modalService
260260
.open(new ConfirmModal("Are you sure?", "Are you sure about accepting this?"))
261-
.onApprove(() => alert("accepted!"))
262-
.onDeny(() => alert("denied!"));
261+
.onApprove(() => alert("User has accepted."))
262+
.onDeny(() => alert("User has denied."));
263263
}
264264
}
265265

0 commit comments

Comments
 (0)