Skip to content

Commit b3444b2

Browse files
committed
refactor(tabs): use @input() transform
1 parent 001fbe5 commit b3444b2

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

projects/coreui-angular/src/lib/tabs/tab-content-ref.directive.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {
2+
booleanAttribute,
23
ChangeDetectorRef,
34
Directive,
45
HostBinding,
56
HostListener,
67
Input,
8+
numberAttribute,
79
OnChanges,
810
OnDestroy,
911
SimpleChanges
1012
} from '@angular/core';
11-
import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';
1213
import { Subscription } from 'rxjs';
1314

1415
import { TabService } from './tab.service';
@@ -26,7 +27,6 @@ export class TabContentRefDirective implements OnChanges, OnDestroy {
2627
this.subscribeTabService();
2728
}
2829

29-
static ngAcceptInputType_disabled: BooleanInput;
3030
private tabServiceSubscription!: Subscription;
3131

3232
/**
@@ -38,10 +38,11 @@ export class TabContentRefDirective implements OnChanges, OnDestroy {
3838
/**
3939
* Set active state of tab content
4040
* @type boolean
41+
* @default false
4142
*/
42-
@Input()
43+
@Input({ transform: booleanAttribute })
4344
set active(value: boolean) {
44-
const newValue = coerceBooleanProperty(value);
45+
const newValue = value;
4546
if (this._active !== newValue) {
4647
this._active = newValue;
4748
this.changeDetectorRef.detectChanges();
@@ -58,9 +59,9 @@ export class TabContentRefDirective implements OnChanges, OnDestroy {
5859
* Set disabled state of tab content
5960
* @type boolean
6061
*/
61-
@Input()
62+
@Input({ transform: booleanAttribute })
6263
set disabled(value: boolean) {
63-
this._disabled = coerceBooleanProperty(value);
64+
this._disabled = value;
6465
}
6566

6667
get disabled(): boolean {
@@ -73,7 +74,7 @@ export class TabContentRefDirective implements OnChanges, OnDestroy {
7374
* c-tab-pane index respectively
7475
* @type number
7576
*/
76-
@Input() tabPaneIdx = -1;
77+
@Input({ transform: numberAttribute }) tabPaneIdx = -1;
7778

7879
@HostBinding('class')
7980
get hostClasses() {

projects/coreui-angular/src/lib/tabs/tab-content/tab-content.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ import {
88
EventEmitter,
99
HostBinding,
1010
Input,
11+
numberAttribute,
1112
OnChanges,
1213
OnDestroy,
1314
Output,
1415
QueryList,
1516
SimpleChanges
1617
} from '@angular/core';
17-
import { coerceNumberProperty } from '@angular/cdk/coercion';
1818
import { Subscription } from 'rxjs';
1919

2020
import { TabPaneComponent } from '../tab-pane/tab-pane.component';
2121
import { TabService } from '../tab.service';
2222

2323
@Component({
2424
selector: 'c-tab-content',
25-
template: `<ng-content></ng-content>`,
25+
template: '<ng-content />',
2626
styleUrls: ['./tab-content.component.scss'],
2727
changeDetection: ChangeDetectionStrategy.OnPush,
2828
exportAs: 'cTabContent',
@@ -34,19 +34,21 @@ export class TabContentComponent implements AfterContentChecked, AfterContentIni
3434
* Set active tabPane index
3535
* @type number
3636
*/
37-
@Input()
37+
@Input({ transform: numberAttribute })
3838
set activeTabPaneIdx(value: number) {
39-
const newValue = coerceNumberProperty(value);
39+
const newValue = value;
4040
if (this._activeTabPaneIdx != newValue) {
4141
this._activeTabPaneIdx = newValue;
4242
this.activeTabPaneIdxChange.emit(newValue);
4343
this.changeDetectorRef.markForCheck();
4444
this.changeDetectorRef.detectChanges();
4545
}
4646
};
47+
4748
get activeTabPaneIdx() {
4849
return this._activeTabPaneIdx;
4950
}
51+
5052
private _activeTabPaneIdx = -1;
5153

5254
/**
@@ -76,7 +78,7 @@ export class TabContentComponent implements AfterContentChecked, AfterContentIni
7678
ngAfterContentChecked(): void {
7779
this.panes?.forEach((tabPane, index) => {
7880
tabPane.tabContent = this;
79-
tabPane.tabPaneIdx = index;
81+
tabPane.tabPaneIdx = index;
8082
});
8183
this.refreshTabPaneActive(this.activeTabPaneIdx);
8284
this.tabService.setActiveTabIdx({ tabContent: this, activeIdx: this.activeTabPaneIdx });

projects/coreui-angular/src/lib/tabs/tab-pane/tab-pane.component.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { ChangeDetectorRef, Component, HostBinding, OnDestroy } from '@angular/core';
2-
import { coerceBooleanProperty } from '@angular/cdk/coercion';
1+
import { booleanAttribute, ChangeDetectorRef, Component, HostBinding, OnDestroy } from '@angular/core';
32
import { Subscription } from 'rxjs';
43

54
import { TabContentComponent } from '../tab-content/tab-content.component';
65
import { ITabContentState, TabService } from '../tab.service';
76

87
@Component({
98
selector: 'c-tab-pane',
10-
template: `
11-
<ng-content></ng-content>`,
9+
template: '<ng-content />',
1210
styleUrls: ['./tab-pane.component.scss'],
1311
exportAs: 'cTabPane',
1412
standalone: true
@@ -27,7 +25,7 @@ export class TabPaneComponent implements OnDestroy {
2725
private tabServiceSubscription!: Subscription;
2826

2927
set active(value: boolean) {
30-
const newValue = coerceBooleanProperty(value);
28+
const newValue = booleanAttribute(value);
3129
if (this._active !== newValue) {
3230
this._active = newValue;
3331
this.changeDetectorRef.markForCheck();

0 commit comments

Comments
 (0)