Skip to content

Commit 5dea059

Browse files
authored
fix(module:color-picker): avoid emitted twice nzOnChange event (#8530)
1 parent b506206 commit 5dea059

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

components/color-picker/color-format.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ import {
2424
ValidatorFn
2525
} from '@angular/forms';
2626
import { Subject } from 'rxjs';
27-
import { debounceTime, filter, takeUntil } from 'rxjs/operators';
27+
import { debounceTime, distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
2828

2929
import { InputBoolean } from 'ng-zorro-antd/core/util';
3030
import { NzInputDirective, NzInputGroupComponent } from 'ng-zorro-antd/input';
3131
import { NzInputNumberComponent } from 'ng-zorro-antd/input-number';
3232
import { NzSelectModule } from 'ng-zorro-antd/select';
3333

3434
import { generateColor } from './src/util/util';
35-
import { NzColorPickerFormatType } from './typings';
35+
import { NzColorPickerFormatType, ValidFormKey } from './typings';
3636

3737
@Component({
3838
selector: 'nz-color-format',
@@ -183,6 +183,9 @@ export class NzColorFormatComponent implements OnChanges, OnInit, OnDestroy {
183183
.pipe(
184184
filter(() => this.validateForm.valid),
185185
debounceTime(200),
186+
distinctUntilChanged((prev, current) =>
187+
Object.keys(prev).every(key => prev[key as ValidFormKey] === current[key as ValidFormKey])
188+
),
186189
takeUntil(this.destroy$)
187190
)
188191
.subscribe(value => {

components/color-picker/typings.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,18 @@ export type NzColorPickerFormatType = 'rgb' | 'hex' | 'hsb';
99

1010
export type NzColorPickerTriggerType = 'click' | 'hover';
1111

12+
export interface ValidForm {
13+
isFormat: NzColorPickerFormatType | null;
14+
hex: string | null;
15+
hsbH: number;
16+
hsbS: number;
17+
hsbB: number;
18+
rgbR: number;
19+
rgbG: number;
20+
rgbB: number;
21+
roundA: number;
22+
}
23+
24+
export type ValidFormKey = keyof ValidForm;
25+
1226
export interface NzColor extends Color {}

0 commit comments

Comments
 (0)