Skip to content

Commit

Permalink
feat(typeahead): added support for placement
Browse files Browse the repository at this point in the history
Closes #1767
Closes #1821
  • Loading branch information
mschoudry authored and pkozlowski-opensource committed Sep 6, 2017
1 parent 6123780 commit a053819
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/typeahead/typeahead-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Injectable} from '@angular/core';
import {PlacementArray} from '../util/positioning';

/**
* Configuration service for the NgbTypeahead component.
Expand All @@ -11,4 +12,5 @@ export class NgbTypeaheadConfig {
editable = true;
focusFirst = true;
showHint = false;
placement: PlacementArray = 'bottom-left';
}
12 changes: 10 additions & 2 deletions src/typeahead/typeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {letProto} from 'rxjs/operator/let';
import {_do} from 'rxjs/operator/do';
import {switchMap} from 'rxjs/operator/switchMap';
import {fromEvent} from 'rxjs/observable/fromEvent';
import {positionElements} from '../util/positioning';
import {positionElements, PlacementArray} from '../util/positioning';
import {NgbTypeaheadWindow, ResultTemplateContext} from './typeahead-window';
import {PopupService} from '../util/popup';
import {toString, isDefined} from '../util/util';
Expand Down Expand Up @@ -136,6 +136,13 @@ export class NgbTypeahead implements ControlValueAccessor,
*/
@Input() showHint: boolean;

/** Placement of a typeahead accepts:
* "top", "top-left", "top-right", "bottom", "bottom-left", "bottom-right",
* "left", "left-top", "left-bottom", "right", "right-top", "right-bottom"
* and array of above values.
*/
@Input() placement: PlacementArray = 'bottom-left';

/**
* An event emitted when a match is selected. Event payload is of type NgbTypeaheadSelectItemEvent.
*/
Expand All @@ -155,6 +162,7 @@ export class NgbTypeahead implements ControlValueAccessor,
this.editable = config.editable;
this.focusFirst = config.focusFirst;
this.showHint = config.showHint;
this.placement = config.placement;

this._valueChanges = fromEvent(_elementRef.nativeElement, 'input', ($event) => $event.target.value);

Expand All @@ -166,7 +174,7 @@ export class NgbTypeahead implements ControlValueAccessor,
this._zoneSubscription = ngZone.onStable.subscribe(() => {
if (this.isPopupOpen()) {
positionElements(
this._elementRef.nativeElement, this._windowRef.location.nativeElement, 'bottom-left',
this._elementRef.nativeElement, this._windowRef.location.nativeElement, this.placement,
this.container === 'body');
}
});
Expand Down

0 comments on commit a053819

Please sign in to comment.