Skip to content

Commit 5864767

Browse files
Merge branch 'master' into feat/table-expand-all
2 parents 815a360 + 1ffde64 commit 5864767

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/modal/modal.component.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ export class ModalDemo {
9696
[attr.aria-label]="ariaLabel"
9797
#modal>
9898
<ng-content></ng-content>
99-
<div
100-
*ngIf="hasScrollingContent !== null ? hasScrollingContent : shouldShowScrollbar"
101-
class="cds--modal-content--overflow-indicator">
102-
</div>
10399
</div>
104100
</cds-overlay>
105101
`
@@ -164,7 +160,7 @@ export class Modal implements AfterViewInit, OnChanges, OnDestroy {
164160
private renderer: Renderer2
165161
) { }
166162

167-
ngOnChanges({ open }: SimpleChanges) {
163+
ngOnChanges({ open, hasScrollingContent }: SimpleChanges) {
168164
if (open) {
169165
if (open.currentValue) {
170166
// `100` is just enough time to allow the modal
@@ -179,13 +175,17 @@ export class Modal implements AfterViewInit, OnChanges, OnDestroy {
179175
this.trigger.focus();
180176
}
181177
}
178+
if (hasScrollingContent) {
179+
this.updateScrollbar();
180+
}
182181
}
183182

184183
/**
185184
* Set document focus to be on the modal component after it is initialized.
186185
*/
187186
ngAfterViewInit() {
188187
this.focusInitialElement();
188+
this.updateScrollbar();
189189
}
190190

191191
/**
@@ -244,4 +244,16 @@ export class Modal implements AfterViewInit, OnChanges, OnDestroy {
244244
setTimeout(() => this.modal.nativeElement.focus());
245245
}
246246
}
247+
248+
private updateScrollbar() {
249+
const modalContent = this.modal ? this.modal.nativeElement.querySelector(".cds--modal-content") : null;
250+
const showScrollbar = this.hasScrollingContent !== null ? this.hasScrollingContent : this.shouldShowScrollbar;
251+
if (modalContent) {
252+
if (showScrollbar) {
253+
this.renderer.addClass(modalContent, "cds--modal-scroll-content");
254+
} else {
255+
this.renderer.removeClass(modalContent, "cds--modal-scroll-content");
256+
}
257+
}
258+
}
247259
}

0 commit comments

Comments
 (0)