File tree 2 files changed +33
-3
lines changed
2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,8 @@ const defaultDisplayRender = (labels: string[]): string => labels.join(' / ');
95
95
[(ngModel)]="inputValue"
96
96
(blur)="handleInputBlur()"
97
97
(focus)="handleInputFocus()"
98
+ (compositionstart)="handleInputCompositionstart()"
99
+ (compositionend)="handleInputCompositionend()"
98
100
/>
99
101
</span>
100
102
@if (showLabelRender) {
@@ -109,9 +111,11 @@ const defaultDisplayRender = (labels: string[]): string => labels.join(' / ');
109
111
}
110
112
</span>
111
113
} @else {
112
- <span class="ant-select-selection-placeholder" [style.visibility]="!inputValue ? 'visible' : 'hidden'">{{
113
- showPlaceholder ? nzPlaceHolder || locale?.placeholder : null
114
- }}</span>
114
+ <span
115
+ class="ant-select-selection-placeholder"
116
+ [style.visibility]="isComposing || inputValue ? 'hidden' : 'visible'"
117
+ >{{ showPlaceholder ? nzPlaceHolder || locale?.placeholder : null }}</span
118
+ >
115
119
}
116
120
</div>
117
121
@if (nzShowArrow) {
@@ -340,6 +344,8 @@ export class NzCascaderComponent
340
344
locale ! : NzCascaderI18nInterface ;
341
345
dir : Direction = 'ltr' ;
342
346
347
+ isComposing = false ;
348
+
343
349
private inputString = '' ;
344
350
private isOpening = false ;
345
351
private delayMenuTimer ?: ReturnType < typeof setTimeout > ;
@@ -596,6 +602,14 @@ export class NzCascaderComponent
596
602
this . focus ( ) ;
597
603
}
598
604
605
+ handleInputCompositionstart ( ) : void {
606
+ this . isComposing = true ;
607
+ }
608
+
609
+ handleInputCompositionend ( ) : void {
610
+ this . isComposing = false ;
611
+ }
612
+
599
613
@HostListener ( 'click' )
600
614
onTriggerClick ( ) : void {
601
615
if ( this . nzDisabled ) {
Original file line number Diff line number Diff line change @@ -146,6 +146,22 @@ describe('cascader', () => {
146
146
expect ( getPlaceholder ( ) ) . toBe ( placeholder ) ;
147
147
} ) ;
148
148
149
+ it ( 'should show/hide placeholder when trigger compositionstart/compositionend event' , ( ) => {
150
+ testComponent . nzPlaceHolder = 'placeholder test' ;
151
+ fixture . detectChanges ( ) ;
152
+
153
+ const placeholderElement = cascader . nativeElement . querySelector ( '.ant-select-selection-placeholder' ) ;
154
+ const fakeCompositionstartEvent = createFakeEvent ( 'compositionstart' , true , true ) ;
155
+ getInputEl ( ) . dispatchEvent ( fakeCompositionstartEvent ) ;
156
+ fixture . detectChanges ( ) ;
157
+ expect ( placeholderElement . style . visibility ) . toBe ( 'hidden' ) ;
158
+
159
+ const fakeCompositionendEvent = createFakeEvent ( 'compositionend' , true , true ) ;
160
+ getInputEl ( ) . dispatchEvent ( fakeCompositionendEvent ) ;
161
+ fixture . detectChanges ( ) ;
162
+ expect ( placeholderElement . style . visibility ) . toBe ( 'visible' ) ;
163
+ } ) ;
164
+
149
165
it ( 'should size work' , ( ) => {
150
166
testComponent . nzSize = 'small' ;
151
167
fixture . detectChanges ( ) ;
You can’t perform that action at this time.
0 commit comments