77 EventEmitter ,
88 HostListener ,
99 Input ,
10- Output ,
10+ Output , Renderer2 , SimpleChanges ,
1111 TemplateRef ,
12- ViewChild
12+ ViewChild , OnChanges
1313} from '@angular/core' ;
1414import { AnimationNumberDuration } from 'ng-devui/utils' ;
1515export type IButtonType = 'button' | 'submit' | 'reset' ;
@@ -21,14 +21,14 @@ export type IButtonPosition = 'left' | 'right' | 'default';
2121export type IButtonSize = 'lg' | 'md' | 'sm' | 'xs' ;
2222
2323@Component ( {
24- selector : 'd-button' ,
25- templateUrl : './button.component.html' ,
26- styleUrls : [ './button.component.scss' ] ,
27- changeDetection : ChangeDetectionStrategy . OnPush ,
28- preserveWhitespaces : false ,
29- standalone : false
24+ selector : 'd-button' ,
25+ templateUrl : './button.component.html' ,
26+ styleUrls : [ './button.component.scss' ] ,
27+ changeDetection : ChangeDetectionStrategy . OnPush ,
28+ preserveWhitespaces : false ,
29+ standalone : false
3030} )
31- export class ButtonComponent implements AfterContentChecked {
31+ export class ButtonComponent implements AfterContentChecked , OnChanges {
3232 @Input ( ) id : string ;
3333 @Input ( ) type : IButtonType = 'button' ;
3434 @Input ( ) bsStyle : IButtonStyle = 'primary' ;
@@ -62,7 +62,35 @@ export class ButtonComponent implements AfterContentChecked {
6262 showWave = false ;
6363 isMouseDown = false ;
6464
65- constructor ( private cd : ChangeDetectorRef ) {
65+ constructor (
66+ private cd : ChangeDetectorRef ,
67+ private renderer : Renderer2 ,
68+ private el : ElementRef
69+ ) {
70+ }
71+
72+ ngOnChanges ( changes : SimpleChanges ) {
73+ if ( changes ?. disabled ?. currentValue ) {
74+ this . renderer . setStyle (
75+ this . el . nativeElement ,
76+ 'cursor' ,
77+ 'not-allowed'
78+ ) ;
79+ this . renderer . setStyle (
80+ this . el . nativeElement ,
81+ 'pointer-events' ,
82+ 'none'
83+ ) ;
84+ } else if ( ! changes ?. disabled ?. currentValue ) {
85+ this . renderer . removeStyle (
86+ this . el . nativeElement ,
87+ 'cursor'
88+ ) ;
89+ this . renderer . removeStyle (
90+ this . el . nativeElement ,
91+ 'pointer-events'
92+ ) ;
93+ }
6694 }
6795
6896 // 新增click事件,解决直接在host上使用click,在disabled状态下还能触发事件
0 commit comments