4
4
* Licensed under the MIT License. See License.txt in the project root for license information.
5
5
*/
6
6
7
- import { Component , Input , HostBinding , HostListener } from '@angular/core' ;
7
+ import { Component , Input , HostBinding , HostListener , Renderer2 , ElementRef } from '@angular/core' ;
8
8
import { convertToBoolProperty } from '../helpers' ;
9
9
10
10
/**
@@ -203,6 +203,7 @@ export class NbButtonComponent {
203
203
@HostBinding ( 'attr.aria-disabled' )
204
204
@HostBinding ( 'class.btn-disabled' ) disabled : boolean ;
205
205
206
+ // issue #794
206
207
@HostBinding ( 'attr.tabindex' )
207
208
get tabbable ( ) : string {
208
209
return this . disabled ? '-1' : '0' ;
@@ -256,6 +257,7 @@ export class NbButtonComponent {
256
257
@Input ( 'disabled' )
257
258
set setDisabled ( val : boolean ) {
258
259
this . disabled = convertToBoolProperty ( val ) ;
260
+ this . renderer . setProperty ( this . hostElement . nativeElement , 'disabled' , this . disabled ) ;
259
261
}
260
262
261
263
/**
@@ -276,11 +278,26 @@ export class NbButtonComponent {
276
278
this . outline = convertToBoolProperty ( val ) ;
277
279
}
278
280
281
+ /**
282
+ * @private
283
+ * Keep this handler to partially support anchor disabling.
284
+ * Unlike button, anchor doesn't have 'disabled' DOM property,
285
+ * so handler will be called anyway. We preventing navigation and bubbling.
286
+ * Disabling is partial due to click handlers precedence. Consider example:
287
+ * <a nbButton [disabled]="true" (click)="clickHandler()">...</a>
288
+ * 'clickHandler' will be called before our host listener below. We can't prevent
289
+ * such handlers call.
290
+ */
279
291
@HostListener ( 'click' , [ '$event' ] )
280
292
onClick ( event : Event ) {
281
293
if ( this . disabled ) {
282
294
event . preventDefault ( ) ;
283
295
event . stopImmediatePropagation ( ) ;
284
296
}
285
297
}
298
+
299
+ constructor (
300
+ protected renderer : Renderer2 ,
301
+ protected hostElement : ElementRef < HTMLElement > ,
302
+ ) { }
286
303
}
0 commit comments