components icon indicating copy to clipboard operation
components copied to clipboard

md-input not firing blur event

Open rushi216 opened this issue 10 years ago • 5 comments

Note: for support questions, please use one of these channels: https://github.com/angular/material2/blob/master/CONTRIBUTING.md#question. This repository's issues are reserved for feature requests and bug reports.

  • Do you want to request a feature or report a bug? Bug
  • What is the current behavior? Blur event is not firing on elements, even if we provide <md-input (blur)="logBlur()">.
  • If the current behavior is a bug, please provide steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar. Can't find base plunker for md-input
  • What is the expected behavior? Blur event should fire
  • What is the motivation / use case for changing the behavior?
  • Which version of Angular and Material, and which browser and OS does this issue affect? Did this work in previous versions of Angular / Material? Please also test with the latest stable and snapshot versions. Tested on 2.0.0.alpha-2 in Chrome
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix)

rushi216 avatar Apr 20 '16 09:04 rushi216

@hansl really starting to think we should start poking at the host projection feature after ng-conf...

jelbourn avatar Apr 20 '16 16:04 jelbourn

(input) (focus) ... and other events are also not being emitted for md-input, is this by design or will they be added in the future? thanks in advance

ps :+1: for (blur)

ratscrew avatar May 14 '16 00:05 ratscrew

For any one looking for a stop gap here is a quick and dirty directive:

import {Directive,Output,ViewContainerRef,EventEmitter, OnInit} from '@angular/core';
import {MdInput} from '@angular2-material/input';

@Directive({
    selector:'md-input[blur]'
})
export class mdInputBlurEvent implements OnInit {
    @Output('blur') blur:EventEmitter<any> = new EventEmitter();
    private _component:MdInput;

    constructor( private _vewContainerRef: ViewContainerRef){ }

    ngOnInit() {
        let me = this;
        me._component = (<any>me._vewContainerRef)._element.component

        me._component['onBlur'] = ()=>{
          me.onBlur();
        }
    }

    onBlur() {
        this.blur.next({target:{value:this._component.value}});
        (<any>this._component)._focused = false;
        (<any>this._component)._onTouchedCallback();
    }

}

ratscrew avatar May 14 '16 02:05 ratscrew

thanks @robertmesserle

ratscrew avatar May 16 '16 18:05 ratscrew

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.