UNPKG

carbon-components-angular

Version:
1,341 lines (1,196 loc) 67.2 kB
<!doctype html> <html class="no-js" lang=""> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title>carbon-components-angular documentation</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="../images/favicon.ico"> <link rel="stylesheet" href="../styles/style.css"> <link rel="stylesheet" href="../styles/dark.css"> </head> <body> <div class="navbar navbar-default navbar-fixed-top d-block d-sm-none"> <a href="../" class="navbar-brand">carbon-components-angular documentation</a> <button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button> </div> <div class="xs-menu menu" id="mobile-menu"> <div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div> <compodoc-menu></compodoc-menu> </div> <div class="container-fluid main"> <div class="row main"> <div class="hidden-xs menu"> <compodoc-menu mode="normal"></compodoc-menu> </div> <!-- START CONTENT --> <div class="content component"> <div class="content-data"> <ol class="breadcrumb"> <li class="breadcrumb-item">Components</li> <li class="breadcrumb-item" > Modal</li> </ol> <ul class="nav nav-tabs" role="tablist"> <li class="nav-item"> <a href="#info" class="nav-link active" role="tab" id="info-tab" data-bs-toggle="tab" data-link="info">Info</a> </li> <li class="nav-item"> <a href="#source" class="nav-link" role="tab" id="source-tab" data-bs-toggle="tab" data-link="source">Source</a> </li> <li class="nav-item"> <a href="#tree" class="nav-link" role="tab" id="tree-tab" data-bs-toggle="tab" data-link="dom-tree">DOM Tree</a> </li> </ul> <div class="tab-content"> <div class="tab-pane fade active in" id="info"><p class="comment"> <h3>File</h3> </p> <p class="comment"> <code>src/modal/modal.component.ts</code> </p> <p class="comment"> <h3>Description</h3> </p> <p class="comment"> <p>Component to create modals for presenting content.</p> <p><a href="../../?path=/story/components-modal--basic">See demo</a></p> <p>Using a modal in your application requires <code>cds-placeholder</code> which would generally be placed near the end of your app component template (app.component.ts or app.component.html) as:</p> <div><pre class="line-numbers"><code class="language-html">&lt;cds-placeholder&gt;&lt;/cds-placeholder&gt;</code></pre></div><p>A more complete example for <code>Modal</code> is given as follows:</p> <p>Example modal definition:</p> <div><pre class="line-numbers"><code class="language-typescript">&#64;Component({ selector: &quot;app-sample-modal&quot;, template: ` &lt;cds-modal size=&quot;xl&quot; (overlaySelected)=&quot;closeModal()&quot;&gt; &lt;cds-modal-header (closeSelect)=&quot;closeModal()&quot;&gt;Header text&lt;/cds-modal-header&gt; &lt;section class=&quot;modal-body&quot;&gt; &lt;h1&gt;Sample modal works.&lt;/h1&gt; &lt;button class=&quot;btn--icon-link&quot; nPopover=&quot;Hello there&quot; title=&quot;Popover title&quot; placement=&quot;right&quot; appendInline=&quot;true&quot;&gt; &lt;svg cdsIcon=&quot;info&quot; size=&quot;sm&quot;&gt;&lt;/svg&gt; &lt;/button&gt; {{modalText}} &lt;/section&gt; &lt;cds-modal-footer&gt;&lt;button cdsButton=&quot;primary&quot; (click)=&quot;closeModal()&quot;&gt;Close&lt;/button&gt;&lt;/cds-modal-footer&gt; &lt;/cds-modal&gt;`, styleUrls: [&quot;./sample-modal.component.scss&quot;] }) export class SampleModal extends BaseModal { modalText: string; constructor(protected injector: Injector) { super(); this.modalText = this.injector.get(&quot;modalText&quot;); } }</code></pre></div><p>Example of opening the modal:</p> <div><pre class="line-numbers"><code class="language-typescript">&#64;Component({ selector: &quot;app-modal-demo&quot;, template: ` &lt;button cdsButton=&quot;primary&quot; (click)=&quot;openModal(&#39;drill&#39;)&quot;&gt;Drill-down modal&lt;/button&gt; &lt;cds-placeholder&gt;&lt;/cds-placeholder&gt;` }) export class ModalDemo { openModal() { this.modalService.create({component: SampleModal, inputs: {modalText: &quot;Hello universe.&quot;}}); } }</code></pre></div> </p> <p class="comment"> <h3>Implements</h3> </p> <p class="comment"> <code>AfterViewInit</code> <code>OnChanges</code> <code>OnDestroy</code> </p> <section data-compodoc="block-metadata"> <h3>Metadata</h3> <table class="table table-sm table-hover metadata"> <tbody> <tr> <td class="col-md-3">selector</td> <td class="col-md-9"><code>cds-modal, ibm-modal</code></td> </tr> <tr> <td class="col-md-3">template</td> <td class="col-md-9"><pre class="line-numbers"><code class="language-html">&lt;cds-overlay [theme]&#x3D;&quot;theme&quot; [open]&#x3D;&quot;open&quot; (overlaySelect)&#x3D;&quot;overlaySelected.emit()&quot;&gt; &lt;div class&#x3D;&quot;cds--modal-container&quot; [ngClass]&#x3D;&quot;{ &#x27;cds--modal-container--xs&#x27;: size &#x3D;&#x3D;&#x3D; &#x27;xs&#x27;, &#x27;cds--modal-container--sm&#x27;: size &#x3D;&#x3D;&#x3D; &#x27;sm&#x27;, &#x27;cds--modal-container--md&#x27;: size &#x3D;&#x3D;&#x3D; &#x27;md&#x27;, &#x27;cds--modal-container--lg&#x27;: size &#x3D;&#x3D;&#x3D; &#x27;lg&#x27; }&quot; role&#x3D;&quot;dialog&quot; aria-modal&#x3D;&quot;true&quot; style&#x3D;&quot;z-index:1;&quot; [attr.aria-label]&#x3D;&quot;ariaLabel&quot; #modal&gt; &lt;ng-content&gt;&lt;/ng-content&gt; &lt;div *ngIf&#x3D;&quot;hasScrollingContent !&#x3D;&#x3D; null ? hasScrollingContent : shouldShowScrollbar&quot; class&#x3D;&quot;cds--modal-content--overflow-indicator&quot;&gt; &lt;/div&gt; &lt;/div&gt; &lt;/cds-overlay&gt; </code></pre></td> </tr> </tbody> </table> </section> <section data-compodoc="block-index"> <h3 id="index">Index</h3> <table class="table table-sm table-bordered index-table"> <tbody> <tr> <td class="col-md-4"> <h6><b>Properties</b></h6> </td> </tr> <tr> <td class="col-md-4"> <ul class="index-list"> <li> <span class="modifier"></span> <a href="#modal" >modal</a> </li> <li> <span class="modifier">Public</span> <a href="#modalService" >modalService</a> </li> <li> <a href="#selectorPrimaryFocus" >selectorPrimaryFocus</a> </li> </ul> </td> </tr> <tr> <td class="col-md-4"> <h6><b>Methods</b></h6> </td> </tr> <tr> <td class="col-md-4"> <ul class="index-list"> <li> <span class="modifier">Protected</span> <a href="#focusInitialElement" >focusInitialElement</a> </li> <li> <span class="modifier"></span> <a href="#handleKeyboardEvent" >handleKeyboardEvent</a> </li> <li> <a href="#ngAfterViewInit" >ngAfterViewInit</a> </li> <li> <a href="#ngOnChanges" >ngOnChanges</a> </li> <li> <a href="#ngOnDestroy" >ngOnDestroy</a> </li> </ul> </td> </tr> <tr> <td class="col-md-4"> <h6><b>Inputs</b></h6> </td> </tr> <tr> <td class="col-md-4"> <ul class="index-list"> <li> <a href="#ariaLabel" >ariaLabel</a> </li> <li> <a href="#hasScrollingContent" >hasScrollingContent</a> </li> <li> <a href="#open" >open</a> </li> <li> <a href="#size" >size</a> </li> <li> <a href="#theme" >theme</a> </li> <li> <a href="#trigger" >trigger</a> </li> </ul> </td> </tr> <tr> <td class="col-md-4"> <h6><b>Outputs</b></h6> </td> </tr> <tr> <td class="col-md-4"> <ul class="index-list"> <li> <a href="#close" >close</a> </li> <li> <a href="#overlaySelected" >overlaySelected</a> </li> </ul> </td> </tr> <tr> <td class="col-md-4"> <h6><b>HostListeners</b></h6> </td> </tr> <tr> <td class="col-md-4"> <ul class="index-list"> <li> <a href="#keydown" >keydown</a> </li> </ul> </td> </tr> <tr> <td class="col-md-4"> <h6><b>Accessors</b></h6> </td> </tr> <tr> <td class="col-md-4"> <ul class="index-list"> <li> <a href="#shouldShowScrollbar" >shouldShowScrollbar</a> </li> </ul> </td> </tr> </tbody> </table> </section> <section data-compodoc="block-constructor"> <h3 id="constructor">Constructor</h3> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <code>constructor(modalService: <a href="../injectables/BaseModalService.html" target="_self">BaseModalService</a>, document: Document, renderer: Renderer2)</code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="156" class="link-to-prism">src/modal/modal.component.ts:156</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Creates an instance of <code>Modal</code>.</p> </div> <div> <b>Parameters :</b> <table class="params"> <thead> <tr> <td>Name</td> <td>Type</td> <td>Optional</td> </tr> </thead> <tbody> <tr> <td>modalService</td> <td> <code><a href="../injectables/BaseModalService.html" target="_self" >BaseModalService</a></code> </td> <td> No </td> </tr> <tr> <td>document</td> <td> <code>Document</code> </td> <td> No </td> </tr> <tr> <td>renderer</td> <td> <code>Renderer2</code> </td> <td> No </td> </tr> </tbody> </table> </div> </td> </tr> </tbody> </table> </section> <section data-compodoc="block-inputs"> <h3 id="inputs">Inputs</h3> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="ariaLabel"></a> <b>ariaLabel</b> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code> </td> </tr> <tr> <td class="col-md-4"> <i>Default value : </i><code>&quot;default&quot;</code> </td> </tr> <tr> <td class="col-md-2" colspan="2"> <div class="io-line">Defined in <a href="" data-line="120" class="link-to-prism">src/modal/modal.component.ts:120</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Label for the modal.</p> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="hasScrollingContent"></a> <b>hasScrollingContent</b> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/boolean" target="_blank" >boolean</a></code> </td> </tr> <tr> <td class="col-md-4"> <i>Default value : </i><code>null</code> </td> </tr> <tr> <td class="col-md-2" colspan="2"> <div class="io-line">Defined in <a href="" data-line="138" class="link-to-prism">src/modal/modal.component.ts:138</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Specify whether the modal contains scrolling content. This property overrides the automatic detection of the existence of scrolling content. Set this property to <code>true</code> to force overflow indicator to show up or to <code>false</code> to force overflow indicator to disappear. It is set to <code>null</code> by default which indicates not to override automatic detection.</p> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="open"></a> <b>open</b> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/boolean" target="_blank" >boolean</a></code> </td> </tr> <tr> <td class="col-md-4"> <i>Default value : </i><code>false</code> </td> </tr> <tr> <td class="col-md-2" colspan="2"> <div class="io-line">Defined in <a href="" data-line="125" class="link-to-prism">src/modal/modal.component.ts:125</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Controls the visibility of the modal when used directly in a template</p> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="size"></a> <b>size</b> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code>&quot;xs&quot; | &quot;sm&quot; | &quot;md&quot; | &quot;lg&quot;</code> </td> </tr> <tr> <td class="col-md-4"> <i>Default value : </i><code>&quot;md&quot;</code> </td> </tr> <tr> <td class="col-md-2" colspan="2"> <div class="io-line">Defined in <a href="" data-line="111" class="link-to-prism">src/modal/modal.component.ts:111</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Size of the modal to display.</p> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="theme"></a> <b>theme</b> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code>&quot;default&quot; | &quot;danger&quot;</code> </td> </tr> <tr> <td class="col-md-4"> <i>Default value : </i><code>&quot;default&quot;</code> </td> </tr> <tr> <td class="col-md-2" colspan="2"> <div class="io-line">Defined in <a href="" data-line="115" class="link-to-prism">src/modal/modal.component.ts:115</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Classification of the modal.</p> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="trigger"></a> <b>trigger</b> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code>HTMLElement</code> </td> </tr> <tr> <td class="col-md-2" colspan="2"> <div class="io-line">Defined in <a href="" data-line="130" class="link-to-prism">src/modal/modal.component.ts:130</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>The element that triggers the modal, which should receive focus when the modal closes</p> </div> </td> </tr> </tbody> </table> </section> <section data-compodoc="block-outputs"> <h3 id="outputs">Outputs</h3> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="close"></a> <b>close</b> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code>EventEmitter</code> </td> </tr> <tr> <td class="col-md-2" colspan="2"> <div class="io-line">Defined in <a href="" data-line="147" class="link-to-prism">src/modal/modal.component.ts:147</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>To emit the closing event of the modal window.</p> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="overlaySelected"></a> <b>overlaySelected</b> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code>EventEmitter</code> </td> </tr> <tr> <td class="col-md-2" colspan="2"> <div class="io-line">Defined in <a href="" data-line="143" class="link-to-prism">src/modal/modal.component.ts:143</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Emits event when click occurs within <code>n-overlay</code> element. This is to track click events occurring outside bounds of the <code>Modal</code> object.</p> </div> </td> </tr> </tbody> </table> </section> <section data-compodoc="block-methods"> <h3>HostListeners</h3> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="keydown"></a> <span class="name"> <span ><b>keydown</b></span> <a href="#keydown"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <i>Arguments : </i><code>'$event' </code> </td> </tr> <tr> <td class="col-md-4"> <code>keydown(event: KeyboardEvent)</code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="195" class="link-to-prism">src/modal/modal.component.ts:195</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Handle keyboard events to close modal and tab through the content within the modal.</p> </div> </td> </tr> </tbody> </table> </section> <section data-compodoc="block-methods"> <h3 id="methods"> Methods </h3> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="focusInitialElement"></a> <span class="name"> <span class="modifier">Protected</span> <span ><b>focusInitialElement</b></span> <a href="#focusInitialElement"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <span class="modifier-icon icon ion-ios-reset"></span> <code>focusInitialElement()</code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="237" class="link-to-prism">src/modal/modal.component.ts:237</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"> <b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="handleKeyboardEvent"></a> <span class="name"> <span class="modifier"></span> <span ><b>handleKeyboardEvent</b></span> <a href="#handleKeyboardEvent"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <span class="modifier-icon icon ion-ios-reset"></span> <code>handleKeyboardEvent(event: KeyboardEvent)</code> </td> </tr> <tr> <td class="col-md-4"> <b>Decorators : </b> <br /> <code>@HostListener(&#x27;keydown&#x27;, [&#x27;$event&#x27;])<br /></code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="195" class="link-to-prism">src/modal/modal.component.ts:195</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Handle keyboard events to close modal and tab through the content within the modal.</p> </div> <div class="io-description"> <b>Parameters :</b> <table class="params"> <thead> <tr> <td>Name</td> <td>Type</td> <td>Optional</td> </tr> </thead> <tbody> <tr> <td>event</td> <td> <code>KeyboardEvent</code> </td> <td> No </td> </tr> </tbody> </table> </div> <div> </div> <div class="io-description"> <b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code> </div> <div class="io-description"> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="ngAfterViewInit"></a> <span class="name"> <span ><b>ngAfterViewInit</b></span> <a href="#ngAfterViewInit"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <code>ngAfterViewInit()</code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="187" class="link-to-prism">src/modal/modal.component.ts:187</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Set document focus to be on the modal component after it is initialized.</p> </div> <div class="io-description"> <b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="ngOnChanges"></a> <span class="name"> <span ><b>ngOnChanges</b></span> <a href="#ngOnChanges"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <code>ngOnChanges(undefined: SimpleChanges)</code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="167" class="link-to-prism">src/modal/modal.component.ts:167</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"> <b>Parameters :</b> <table class="params"> <thead> <tr> <td>Name</td> <td>Type</td> <td>Optional</td> </tr> </thead> <tbody> <tr> <td> <code>SimpleChanges</code> </td> <td> No </td> </tr> </tbody> </table> </div> <div> </div> <div class="io-description"> <b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code> </div> <div class="io-description"> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="ngOnDestroy"></a> <span class="name"> <span ><b>ngOnDestroy</b></span> <a href="#ngOnDestroy"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <code>ngOnDestroy()</code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="233" class="link-to-prism">src/modal/modal.component.ts:233</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"> <b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code> </div> </td> </tr> </tbody> </table> </section> <section data-compodoc="block-properties"> <h3 id="inputs"> Properties </h3> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="modal"></a> <span class="name"> <span class="modifier"></span> <span ><b>modal</b></span> <a href="#modal"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code>ElementRef</code> </td> </tr> <tr> <td class="col-md-4"> <b>Decorators : </b> <br /> <code> @ViewChild(&#x27;modal&#x27;, {static: true})<br /> </code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="151" class="link-to-prism">src/modal/modal.component.ts:151</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>Maintains a reference to the view DOM element of the <code>Modal</code>.</p> </div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="modalService"></a> <span class="name"> <span class="modifier">Public</span> <span ><b>modalService</b></span> <a href="#modalService"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code><a href="../injectables/BaseModalService.html" target="_self" >BaseModalService</a></code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="162" class="link-to-prism">src/modal/modal.component.ts:162</a></div> </td> </tr> </tbody> </table> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="selectorPrimaryFocus"></a> <span class="name"> <span ><b>selectorPrimaryFocus</b></span> <a href="#selectorPrimaryFocus"><span class="icon ion-ios-link"></span></a> </span> </td> </tr> <tr> <td class="col-md-4"> <i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code> </td> </tr> <tr> <td class="col-md-4"> <i>Default value : </i><code>&quot;[modal-primary-focus]&quot;</code> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="156" class="link-to-prism">src/modal/modal.component.ts:156</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>An element should have &#39;modal-primary-focus&#39; as an attribute to receive initial focus within the <code>Modal</code> component.</p> </div> </td> </tr> </tbody> </table> </section> <section data-compodoc="block-accessors"> <h3 id="accessors"> Accessors </h3> <table class="table table-sm table-bordered"> <tbody> <tr> <td class="col-md-4"> <a name="shouldShowScrollbar"></a> <span class="name"><b>shouldShowScrollbar</b><a href="#shouldShowScrollbar"><span class="icon ion-ios-link"></span></a></span> </td> </tr> <tr> <td class="col-md-4"> <span class="accessor"><b>get</b><code>shouldShowScrollbar()</code></span> </td> </tr> <tr> <td class="col-md-4"> <div class="io-line">Defined in <a href="" data-line="220" class="link-to-prism">src/modal/modal.component.ts:220</a></div> </td> </tr> <tr> <td class="col-md-4"> <div class="io-description"><p>This detects whether or not the modal contains scrolling content.</p> <p>To force trigger a detection (ie. on window resize), change or reset the value of the modal content.</p> <p>Use the <code>hasScrollingContent</code> input to manually override the overflow indicator.</p> </div> </td> </tr> </tbody> </table> </section> </div> <div class="tab-pane fade tab-source-code" id="source"> <pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { AfterViewInit, Component, EventEmitter, HostListener, Input, Output, ElementRef, ViewChild, SimpleChanges, OnChanges, Renderer2, Inject, OnDestroy } from &quot;@angular/core&quot;; import { DOCUMENT } from &quot;@angular/common&quot;; import { cycleTabs, getFocusElementList } from &quot;carbon-components-angular/common&quot;; import { BaseModalService } from &quot;./base-modal.service&quot;; /** * Component to create modals for presenting content. * * [See demo](../../?path&#x3D;/story/components-modal--basic) * * Using a modal in your application requires &#x60;cds-placeholder&#x60; which would generally be * placed near the end of your app component template (app.component.ts or app.component.html) as: * &#x60;&#x60;&#x60;html &lt;cds-placeholder&gt;&lt;/cds-placeholder&gt; &#x60;&#x60;&#x60; * * A more complete example for &#x60;Modal&#x60; is given as follows: * * Example modal definition: * &#x60;&#x60;&#x60;typescript @Component({ selector: &quot;app-sample-modal&quot;, template: &#x60; &lt;cds-modal size&#x3D;&quot;xl&quot; (overlaySelected)&#x3D;&quot;closeModal()&quot;&gt; &lt;cds-modal-header (closeSelect)&#x3D;&quot;closeModal()&quot;&gt;Header text&lt;/cds-modal-header&gt; &lt;section class&#x3D;&quot;modal-body&quot;&gt; &lt;h1&gt;Sample modal works.&lt;/h1&gt; &lt;button class&#x3D;&quot;btn--icon-link&quot; nPopover&#x3D;&quot;Hello there&quot; title&#x3D;&quot;Popover title&quot; placement&#x3D;&quot;right&quot; appendInline&#x3D;&quot;true&quot;&gt; &lt;svg cdsIcon&#x3D;&quot;info&quot; size&#x3D;&quot;sm&quot;&gt;&lt;/svg&gt; &lt;/button&gt; {{modalText}} &lt;/section&gt; &lt;cds-modal-footer&gt;&lt;button cdsButton&#x3D;&quot;primary&quot; (click)&#x3D;&quot;closeModal()&quot;&gt;Close&lt;/button&gt;&lt;/cds-modal-footer&gt; &lt;/cds-modal&gt;&#x60;, styleUrls: [&quot;./sample-modal.component.scss&quot;] }) export class SampleModal extends BaseModal { modalText: string; constructor(protected injector: Injector) { super(); this.modalText &#x3D; this.injector.get(&quot;modalText&quot;); } } &#x60;&#x60;&#x60; * * Example of opening the modal: * &#x60;&#x60;&#x60;typescript @Component({ selector: &quot;app-modal-demo&quot;, template: &#x60; &lt;button cdsButton&#x3D;&quot;primary&quot; (click)&#x3D;&quot;openModal(&#x27;drill&#x27;)&quot;&gt;Drill-down modal&lt;/button&gt; &lt;cds-placeholder&gt;&lt;/cds-placeholder&gt;&#x60; }) export class ModalDemo { openModal() { this.modalService.create({component: SampleModal, inputs: {modalText: &quot;Hello universe.&quot;}}); } } &#x60;&#x60;&#x60; */ @Component({ selector: &quot;cds-modal, ibm-modal&quot;, template: &#x60; &lt;cds-overlay [theme]&#x3D;&quot;theme&quot; [open]&#x3D;&quot;open&quot; (overlaySelect)&#x3D;&quot;overlaySelected.emit()&quot;&gt; &lt;div class&#x3D;&quot;cds--modal-container&quot; [ngClass]&#x3D;&quot;{ &#x27;cds--modal-container--xs&#x27;: size &#x3D;&#x3D;&#x3D; &#x27;xs&#x27;, &#x27;cds--modal-container--sm&#x27;: size &#x3D;&#x3D;&#x3D; &#x27;sm&#x27;, &#x27;cds--modal-container--md&#x27;: size &#x3D;&#x3D;&#x3D; &#x27;md&#x27;, &#x27;cds--modal-container--lg&#x27;: size &#x3D;&#x3D;&#x3D; &#x27;lg&#x27; }&quot; role&#x3D;&quot;dialog&quot; aria-modal&#x3D;&quot;true&quot; style&#x3D;&quot;z-index:1;&quot; [attr.aria-label]&#x3D;&quot;ariaLabel&quot; #modal&gt; &lt;ng-content&gt;&lt;/ng-content&gt; &lt;div *ngIf&#x3D;&quot;hasScrollingContent !&#x3D;&#x3D; null ? hasScrollingContent : shouldShowScrollbar&quot; class&#x3D;&quot;cds--modal-content--overflow-indicator&quot;&gt; &lt;/div&gt; &lt;/div&gt; &lt;/cds-overlay&gt; &#x60; }) export class Modal implements AfterViewInit, OnChanges, OnDestroy { /** * Size of the modal to display. */ @Input() size: &quot;xs&quot; | &quot;sm&quot;| &quot;md&quot; | &quot;lg&quot; &#x3D; &quot;md&quot;; /** * Classification of the modal. */ @Input() theme: &quot;default&quot; | &quot;danger&quot; &#x3D; &quot;default&quot;; /** * Label for the modal. */ @Input() ariaLabel &#x3D; &quot;default&quot;; /** * Controls the visibility of the modal when used directly in a template */ @Input() open &#x3D; false; /** * The element that triggers the modal, which should receive focus when the modal closes */ @Input() trigger: HTMLElement; /** * Specify whether the modal contains scrolling content. This property overrides the automatic * detection of the existence of scrolling content. Set this property to &#x60;true&#x60; to force * overflow indicator to show up or to &#x60;false&#x60; to force overflow indicator to disappear. * It is set to &#x60;null&#x60; by default which indicates not to override automatic detection. */ @Input() hasScrollingContent: boolean &#x3D; null; /** * Emits event when click occurs within &#x60;n-overlay&#x60; element. This is to track click events occurring outside bounds of the &#x60;Modal&#x60; object. */ @Output() overlaySelected &#x3D; new EventEmitter(); /** * To emit the closing event of the modal window. */ @Output() close &#x3D; new EventEmitter(); /** * Maintains a reference to the view DOM element of the &#x60;Modal&#x60;. */ @ViewChild(&quot;modal&quot;, { static: true }) modal: ElementRef; /** * An element should have &#x27;modal-primary-focus&#x27; as an attribute to receive initial focus within the &#x60;Modal&#x60; component. */ selectorPrimaryFocus &#x3D; &quot;[modal-primary-focus]&quot;; /** * Creates an instance of &#x60;Modal&#x60;. */ constructor( public modalService: BaseModalService, @Inject(DOCUMENT) private document: Document, private renderer: Renderer2 ) { } ngOnChanges({ open }: SimpleChanges) { if (open) { if (open.currentValue) { // &#x60;100&#x60; is just enough time to allow the modal // to become visible, so that we can set focus setTimeout(() &#x3D;&gt; this.focusInitialElement(), 100); // Prevent scrolling on open this.renderer.addClass(this.document.body, &quot;cds--body--with-modal-open&quot;); } else if (!open.currentValue) { // Enable scrolling on close this.renderer.removeClass(this.document.body, &quot;cds--body--with-modal-open&quot;); } else if (this.trigger) { this.trigger.focus(); } } } /** * Set document focus to be on the modal component after it is initialized. */ ngAfterViewInit() { this.focusInitialElement(); } /** * Handle keyboard events to close modal and tab through the content within the modal. */ @HostListener(&quot;keydown&quot;, [&quot;$event&quot;]) handleKeyboardEvent(event: KeyboardEvent) { switch (event.key) { case &quot;Escape&quot;: { event.stopImmediatePropagation(); // prevents events being fired for multiple modals if more than 2 open // Manually close modal this.open &#x3D; false; this.close.emit(); this.modalService.destroy(); // destroy top (latest) modal break; } case &quot;Tab&quot;: { cycleTabs(event, this.modal.nativeElement); break; } } } /** * This detects whether or not the modal contains scrolling content. * * To force trigger a detection (ie. on window resize), change or reset the value of the modal content. * * Use the &#x60;hasScrollingContent&#x60; input to manually override the overflow indicator. */ get shouldShowScrollbar() { const modalContent &#x3D; this.modal ? this.modal.nativeElement.querySelector(&quot;.cds--modal-content&quot;) : null; if (modalContent) { // get rounded value