|
1 |
| -import { |
2 |
| - booleanAttribute, |
3 |
| - computed, |
4 |
| - Directive, |
5 |
| - HostBinding, |
6 |
| - input, |
7 |
| - InputSignal, |
8 |
| - InputSignalWithTransform |
9 |
| -} from '@angular/core'; |
| 1 | +import { booleanAttribute, computed, Directive, input, InputSignal, InputSignalWithTransform } from '@angular/core'; |
10 | 2 |
|
11 | 3 | import { ButtonType, Colors, Shapes } from '../coreui.types';
|
12 | 4 |
|
13 | 5 | @Directive({
|
14 | 6 | selector: '[cButton]',
|
15 | 7 | exportAs: 'cButton',
|
16 | 8 | standalone: true,
|
17 |
| - host: { class: 'btn', '[class]': 'hostClasses()', '[attr.type]': 'type()' } |
| 9 | + host: { |
| 10 | + class: 'btn', |
| 11 | + '[class]': 'hostClasses()', |
| 12 | + '[attr.aria-disabled]': 'ariaDisabled()', |
| 13 | + '[attr.aria-pressed]': 'isActive()', |
| 14 | + '[attr.disabled]': 'attrDisabled()', |
| 15 | + '[attr.tabindex]': 'tabIndex()', |
| 16 | + '[attr.type]': 'type()' |
| 17 | + } |
18 | 18 | })
|
19 | 19 | export class ButtonDirective {
|
20 | 20 | /**
|
@@ -69,28 +69,26 @@ export class ButtonDirective {
|
69 | 69 | [`btn-${this.variant()}-${this.color()}`]: !!this.variant() && !!this.color(),
|
70 | 70 | [`btn-${this.size()}`]: !!this.size(),
|
71 | 71 | [`${this.shape()}`]: !!this.shape(),
|
72 |
| - disabled: this.disabled(), |
73 |
| - active: this.active() |
| 72 | + active: this.active(), |
| 73 | + disabled: this._disabled() |
74 | 74 | } as Record<string, boolean>;
|
75 | 75 | });
|
76 | 76 |
|
77 |
| - @HostBinding('attr.aria-disabled') |
78 |
| - get ariaDisabled() { |
79 |
| - return this.disabled() || null; |
80 |
| - } |
| 77 | + _disabled = computed(() => this.disabled()); |
81 | 78 |
|
82 |
| - @HostBinding('attr.aria-pressed') |
83 |
| - get isActive(): boolean | null { |
84 |
| - return <boolean>this.active() || null; |
85 |
| - } |
| 79 | + ariaDisabled = computed(() => { |
| 80 | + return this._disabled() ? true : null; |
| 81 | + }); |
86 | 82 |
|
87 |
| - @HostBinding('attr.disabled') |
88 |
| - get attrDisabled() { |
89 |
| - return this.disabled() ? '' : null; |
90 |
| - } |
| 83 | + attrDisabled = computed(() => { |
| 84 | + return this._disabled() ? '' : null; |
| 85 | + }); |
91 | 86 |
|
92 |
| - @HostBinding('attr.tabindex') |
93 |
| - get tabIndex(): string | null { |
94 |
| - return this.disabled() ? '-1' : null; |
95 |
| - } |
| 87 | + tabIndex = computed(() => { |
| 88 | + return this._disabled() ? '-1' : null; |
| 89 | + }); |
| 90 | + |
| 91 | + isActive = computed(() => { |
| 92 | + return <boolean>this.active() || null; |
| 93 | + }); |
96 | 94 | }
|
0 commit comments