Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/core/src/directives/keyboard.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class MatKeyboardDirective implements OnDestroy {

@Input() matKeyboard: string;

@Input() active: boolean = true;

@Input() anchor: string = 'bottom';

@Input() darkTheme: boolean;

@Input() duration: number;
Expand All @@ -29,20 +33,25 @@ export class MatKeyboardDirective implements OnDestroy {
@Output() shiftClick: EventEmitter<void> = new EventEmitter<void>();

constructor(private _elementRef: ElementRef,
private _keyboardService: MatKeyboardService,
@Optional() @Self() private _control?: NgControl) {}
private _keyboardService: MatKeyboardService,
@Optional() @Self() private _control?: NgControl) { }

ngOnDestroy() {
this.hideKeyboard();
}

@HostListener('focus', ['$event'])
public showKeyboard() {

if (!this.active) {
return;
}

this._keyboardRef = this._keyboardService.open(this.matKeyboard, {
darkTheme: this.darkTheme,
duration: this.duration,
isDebug: this.isDebug
});
}, this.anchor);

// reference the input element
this._keyboardRef.instance.setInputInstance(this._elementRef);
Expand Down
33 changes: 23 additions & 10 deletions src/core/src/services/keyboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class MatKeyboardService {

private _availableLocales: ILocaleMap = {};

/** Reference to the anchor position (top/bottom) */
private _anchor: string;

/** Reference to the currently opened keyboard at *any* level. */
private get _openedKeyboardRef(): MatKeyboardRef<MatKeyboardComponent> | null {
const parent = this._parentKeyboard;
Expand All @@ -50,10 +53,10 @@ export class MatKeyboardService {
}

constructor(private _overlay: Overlay,
private _live: LiveAnnouncer,
@Inject(LOCALE_ID) private _defaultLocale: string,
@Inject(MAT_KEYBOARD_LAYOUTS) private _layouts: IKeyboardLayouts,
@Optional() @SkipSelf() private _parentKeyboard: MatKeyboardService) {
private _live: LiveAnnouncer,
@Inject(LOCALE_ID) private _defaultLocale: string,
@Inject(MAT_KEYBOARD_LAYOUTS) private _layouts: IKeyboardLayouts,
@Optional() @SkipSelf() private _parentKeyboard: MatKeyboardService) {
// prepare available layouts mapping
this._availableLocales = _applyAvailableLayouts(_layouts);
}
Expand Down Expand Up @@ -131,9 +134,11 @@ export class MatKeyboardService {
* @param layoutOrLocale A string representing the locale or the layout name to be used.
* @param config Additional configuration options for the keyboard.
*/
open(layoutOrLocale: string = this._defaultLocale, config: MatKeyboardConfig = {}): MatKeyboardRef<MatKeyboardComponent> {
open(layoutOrLocale: string = this._defaultLocale, config: MatKeyboardConfig = {}, anchor: string = 'bottom'): MatKeyboardRef<MatKeyboardComponent> {
const _config = _applyConfigDefaults(config);

this._anchor = anchor;

return this.openFromComponent(layoutOrLocale, _config);
}

Expand Down Expand Up @@ -210,11 +215,19 @@ export class MatKeyboardService {
width: '100%'
});

state.positionStrategy = this._overlay
.position()
.global()
.centerHorizontally()
.bottom('0');
if (this._anchor === 'bottom') {
state.positionStrategy = this._overlay
.position()
.global()
.centerHorizontally()
.bottom('0');
} else {
state.positionStrategy = this._overlay
.position()
.global()
.centerHorizontally()
.top('0');
}

return this._overlay.create(state);
}
Expand Down