Skip to content

Commit 31c0dd8

Browse files
authored
fix(cascader): Cascader可搜索demo中每次输入之后会失焦,影响体验 (#250) (#304)
1 parent dbc1ec8 commit 31c0dd8

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

devui/cascader/cascader.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<ng-template #default>
2121
<input
22+
#outerInput
2223
*ngIf="!multiple"
2324
[placeholder]="placeholder"
2425
type="text"
@@ -194,6 +195,7 @@
194195
</div>
195196
<ng-template #default>
196197
<input
198+
#outerInput
197199
*ngIf="!multiple"
198200
[placeholder]="placeholder"
199201
type="text"

devui/cascader/cascader.component.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ const DEBOUNCE_TIME = 200;
1919
templateUrl: './cascader.component.html',
2020
styleUrls: ['./cascader.component.scss'],
2121
providers: [
22-
{
23-
provide: NG_VALUE_ACCESSOR,
24-
useExisting: forwardRef(() => CascaderComponent),
25-
multi: true
26-
},
27-
CascaderService
22+
{
23+
provide: NG_VALUE_ACCESSOR,
24+
useExisting: forwardRef(() => CascaderComponent),
25+
multi: true
26+
},
27+
CascaderService
2828
],
2929
preserveWhitespaces: false
30-
})
30+
})
3131
export class CascaderComponent implements OnInit, OnDestroy, OnChanges, ControlValueAccessor {
3232
@ViewChild('mainDropdown') mainDropdown: DropDownDirective;
3333
@ViewChild('innerInput') innerInput: ElementRef;
34+
@ViewChild('outerInput') outerInput: ElementRef;
3435
@ViewChild(DropDownAppendToBodyComponent, { static: false }) dropdownComp: DropDownAppendToBodyComponent;
3536
@Input() options: CascaderItem[] = [];
3637
@Input() width = 200;
@@ -370,6 +371,10 @@ export class CascaderComponent implements OnInit, OnDestroy, OnChanges, ControlV
370371
}
371372
}
372373

374+
if (isOpen && !this.multiple && this.allowSearch) {
375+
this.outerInput?.nativeElement.focus();
376+
}
377+
373378
if (!isOpen && this.allowSearch) {
374379
if (!this.cascaderSrv.currentValue.length) {
375380
this.showTextValue = null;

0 commit comments

Comments
 (0)