Skip to content

Commit df8a199

Browse files
committed
Commented new modal scrolling functionality
1 parent 58b24c3 commit df8a199

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

components/modal/modal.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class SuiModal<T, U> implements OnInit, AfterViewInit {
104104

105105
public set mustScroll(mustScroll:boolean) {
106106
this._mustScroll = mustScroll;
107+
// 'Cache' value in _mustAlwaysScroll so that if `true`, _mustScroll isn't ever auto-updated.
107108
this._mustAlwaysScroll = mustScroll;
108109
this.updateScroll();
109110
}
@@ -207,14 +208,18 @@ export class SuiModal<T, U> implements OnInit, AfterViewInit {
207208
}
208209
}
209210

211+
// Decides whether the modal needs to reposition to allow scrolling.
210212
private updateScroll() {
213+
// Semantic UI modal margin is 3.5rem, which is relative to the global font size, so for compatibility:
211214
const fontSize = parseFloat(window.getComputedStyle(document.documentElement, null).getPropertyValue('font-size'));
212215
const margin = fontSize * 3.5;
213216

214-
if (this._modalElement) {
217+
// _mustAlwaysScroll works by stopping _mustScroll from being automatically updated, so it stays `true`.
218+
if (!this._mustAlwaysScroll && this._modalElement) {
215219
const element = this._modalElement.nativeElement as Element;
216220

217-
this._mustScroll = !this._mustAlwaysScroll && window.innerHeight < element.clientHeight + margin * 2;
221+
// The modal must scroll if the window height is smaller than the modal height + both margins.
222+
this._mustScroll = window.innerHeight < element.clientHeight + margin * 2;
218223
}
219224
}
220225

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export class ConfirmModal extends ComponentModalConfig<IConfirmModalContext, voi
242242
constructor(title:string, question:string) {
243243
super(ConfirmModalComponent, { title, question });
244244

245+
this.mustScroll = true;
245246
this.isClosable = false;
246247
this.transitionDuration = 200;
247248
this.size = ModalSize.Small;

0 commit comments

Comments
 (0)