Skip to content

Commit f69b73f

Browse files
committed
fix(search-expandable): don't use [disabled] with formControl (#DS-4690) (#1416)
1 parent bd83d4e commit f69b73f

2 files changed

Lines changed: 64 additions & 8 deletions

File tree

packages/components/search-expandable/search-expandable.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
type="button"
44
kbq-button
55
class="kbq-search-expandable__button"
6+
kbqTooltip="{{ localeData.tooltip }}"
67
[color]="'contrast'"
78
[kbqStyle]="'transparent'"
8-
kbqTooltip="{{ localeData.tooltip }}"
9+
[kbqTooltipDisabled]="disabled"
910
[tabIndex]="tabIndex"
1011
[disabled]="disabled"
1112
(click)="toggle()"
@@ -22,7 +23,6 @@
2223
type="text"
2324
autocomplete="off"
2425
[tabIndex]="tabIndex"
25-
[disabled]="disabled"
2626
[placeholder]="placeholder"
2727
[formControl]="$any(ngControl?.control)"
2828
(blur)="onTouch()"

packages/components/search-expandable/search-expandable.spec.ts

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { Component, DebugElement } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
3-
import { FormsModule } from '@angular/forms';
3+
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
44
import { By } from '@angular/platform-browser';
55

6+
import { KbqButton } from '@koobiq/components/button';
7+
import { KbqInput } from '@koobiq/components/input';
68
import { KbqSearchExpandable, KbqSearchExpandableModule } from '@koobiq/components/search-expandable';
79

810
describe('KbqSearchExpandable', () => {
911
let debugElement: DebugElement;
1012
let nativeElement: HTMLElement;
11-
let fixture: ComponentFixture<TestApp>;
13+
let fixture: ComponentFixture<TestSearchExpandable>;
1214

1315
beforeEach(async () => {
1416
await TestBed.configureTestingModule({
15-
imports: [KbqSearchExpandableModule, TestApp]
17+
imports: [KbqSearchExpandableModule, TestSearchExpandable, TestSearchExpandableWithFormControl]
1618
}).compileComponents();
1719
});
1820

1921
beforeEach(() => {
20-
fixture = TestBed.createComponent(TestApp);
22+
fixture = TestBed.createComponent(TestSearchExpandable);
2123
debugElement = fixture.debugElement.query(By.directive(KbqSearchExpandable));
2224
nativeElement = debugElement.nativeElement;
2325
fixture.detectChanges();
@@ -51,17 +53,71 @@ describe('KbqSearchExpandable', () => {
5153
expect(nativeElement.querySelectorAll('.kbq-search-expandable__button').length).toBe(0);
5254
expect(nativeElement.querySelectorAll('.kbq-search-expandable__search').length).toBe(1);
5355
});
56+
57+
it('disabled state', () => {
58+
expect(debugElement.query(By.directive(KbqInput))).toBe(null);
59+
expect(debugElement.query(By.directive(KbqButton)).nativeElement.hasAttribute('disabled')).toBe(false);
60+
61+
fixture.componentInstance.disabled = true;
62+
fixture.detectChanges();
63+
expect(debugElement.query(By.directive(KbqButton)).nativeElement.hasAttribute('disabled')).toBe(true);
64+
65+
fixture.componentInstance.openedState = true;
66+
fixture.detectChanges();
67+
68+
expect(debugElement.query(By.directive(KbqButton))).toBe(null);
69+
expect(debugElement.query(By.directive(KbqInput)).nativeElement.hasAttribute('disabled')).toBe(true);
70+
});
71+
72+
describe('with formControl', () => {
73+
let fixture: ComponentFixture<TestSearchExpandableWithFormControl>;
74+
75+
beforeEach(() => {
76+
fixture = TestBed.createComponent(TestSearchExpandableWithFormControl);
77+
debugElement = fixture.debugElement.query(By.directive(KbqSearchExpandable));
78+
nativeElement = debugElement.nativeElement;
79+
fixture.detectChanges();
80+
});
81+
82+
it('disabled state', () => {
83+
expect(debugElement.query(By.directive(KbqInput))).toBe(null);
84+
expect(debugElement.componentInstance.disabled).toBe(false);
85+
86+
fixture.componentInstance.searchControl.disable();
87+
fixture.componentInstance.openedState = true;
88+
fixture.detectChanges();
89+
90+
expect(debugElement.componentInstance.disabled).toBe(true);
91+
expect(debugElement.query(By.directive(KbqButton))).toBe(null);
92+
expect(debugElement.query(By.directive(KbqInput)).nativeElement.hasAttribute('disabled')).toBe(true);
93+
});
94+
});
5495
});
5596

5697
@Component({
5798
standalone: true,
5899
selector: 'test-app',
59100
imports: [KbqSearchExpandableModule, FormsModule],
60101
template: `
61-
<kbq-search-expandable [isOpened]="openedState" [(ngModel)]="search" />
102+
<kbq-search-expandable [isOpened]="openedState" [disabled]="disabled" [(ngModel)]="search" />
62103
`
63104
})
64-
class TestApp {
105+
class TestSearchExpandable {
65106
openedState: boolean = false;
107+
disabled: boolean = false;
66108
search: string;
67109
}
110+
111+
@Component({
112+
standalone: true,
113+
selector: 'test-app-search-expandable-with-form-control',
114+
imports: [KbqSearchExpandableModule, ReactiveFormsModule],
115+
template: `
116+
<kbq-search-expandable [isOpened]="openedState" [formControl]="searchControl" />
117+
`
118+
})
119+
class TestSearchExpandableWithFormControl {
120+
searchControl = new FormControl<string>('');
121+
122+
openedState: boolean = false;
123+
}

0 commit comments

Comments
 (0)