@@ -55,11 +55,10 @@ import { I18n } from "./../i18n/i18n.module";
5555 </button>
5656 <div
5757 #dropdownMenu
58- *ngIf="!menuIsClosed"
5958 [ngClass]="{
6059 'drop-up': dropUp
6160 }">
62- <ng-content></ng-content>
61+ <ng-content *ngIf="!menuIsClosed" ></ng-content>
6362 </div>
6463 </div>
6564 ` ,
@@ -98,9 +97,23 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
9897 */
9998 @Input ( ) disabled = false ;
10099 /**
100+ * Deprecated. Dropdown now defaults to appending inline
101101 * Set to `true` if the `Dropdown` is to be appended to the DOM body.
102102 */
103- @Input ( ) appendToBody = false ;
103+ @Input ( ) set appendToBody ( v ) {
104+ console . log ( "appendToBody has been deprecated. dropdowns now append to the body by default." ) ;
105+ console . log ( "ensure you have an ibm-placeholder in your app." ) ;
106+ console . log ( "use appendInline if you need to position your dropdowns within the normal page flow" ) ;
107+ this . appendInline = ! v ;
108+ }
109+
110+ get appendToBody ( ) {
111+ return ! this . appendInline ;
112+ }
113+ /**
114+ * set to `true` to place the dropdown view inline with the component
115+ */
116+ @Input ( ) appendInline = false ;
104117 /**
105118 * Query string for the element that contains the `Dropdown`.
106119 * Used to trigger closing the dropdown if it scrolls outside of the viewport of the `scrollableContainer`.
@@ -397,14 +410,11 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
397410 */
398411 _appendToBody ( ) {
399412 const positionDropdown = ( ) => {
400- position . setElement (
401- this . dropdownWrapper ,
402- position . addOffset (
403- position . findAbsolute ( this . elementRef . nativeElement , this . dropdownWrapper , "bottom" ) ,
404- window . scrollY ,
405- window . scrollX
406- )
407- ) ;
413+ let pos = position . findAbsolute ( this . elementRef . nativeElement , this . dropdownWrapper , "bottom" ) ;
414+ // add -40 to the top position to account for carbon styles
415+ pos = position . addOffset ( pos , - 40 , 0 ) ;
416+ pos = position . addOffset ( pos , window . scrollY , window . scrollX ) ;
417+ position . setElement ( this . dropdownWrapper , pos ) ;
408418 } ;
409419 this . dropdownMenu . nativeElement . style . display = "block" ;
410420 this . dropdownWrapper = document . createElement ( "div" ) ;
@@ -426,9 +436,9 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
426436 openMenu ( ) {
427437 this . menuIsClosed = false ;
428438
429- // move the dropdown list to the body if appendToBody is true
439+ // move the dropdown list to the body if we're not appending inline
430440 // and position it relative to the dropdown wrapper
431- if ( this . appendToBody ) {
441+ if ( ! this . appendInline ) {
432442 this . addScrollEventListener ( ) ;
433443 this . _appendToBody ( ) ;
434444 }
@@ -477,7 +487,7 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
477487 }
478488
479489 // move the list back in the component on close
480- if ( this . appendToBody ) {
490+ if ( ! this . appendInline ) {
481491 this . removeScrollEventListener ( ) ;
482492 this . _appendToDropdown ( ) ;
483493 }
@@ -492,7 +502,7 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
492502 */
493503 addScrollEventListener ( ) {
494504 if ( this . scrollableContainer ) {
495- const container = document . querySelector ( this . scrollableContainer ) ;
505+ const container : HTMLElement = document . querySelector ( this . scrollableContainer ) ;
496506
497507 if ( container ) {
498508 this . scroll = fromEvent ( container , "scroll" )
0 commit comments