Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:color-picker): avoid emitted twice nzOnChange event #8530

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions components/color-picker/color-format.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import {
ValidatorFn
} from '@angular/forms';
import { Subject } from 'rxjs';
import { debounceTime, filter, takeUntil } from 'rxjs/operators';
import { debounceTime, distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';

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

import { generateColor } from './src/util/util';
import { NzColorPickerFormatType } from './typings';
import { NzColorPickerFormatType, ValidFormKey } from './typings';

@Component({
selector: 'nz-color-format',
Expand Down Expand Up @@ -183,6 +183,9 @@ export class NzColorFormatComponent implements OnChanges, OnInit, OnDestroy {
.pipe(
filter(() => this.validateForm.valid),
debounceTime(200),
distinctUntilChanged((prev, current) =>
Object.keys(prev).every(key => prev[key as ValidFormKey] === current[key as ValidFormKey])
),
takeUntil(this.destroy$)
)
.subscribe(value => {
Expand Down
14 changes: 14 additions & 0 deletions components/color-picker/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ export type NzColorPickerFormatType = 'rgb' | 'hex' | 'hsb';

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

export interface ValidForm {
isFormat: NzColorPickerFormatType | null;
hex: string | null;
hsbH: number;
hsbS: number;
hsbB: number;
rgbR: number;
rgbG: number;
rgbB: number;
roundA: number;
}

export type ValidFormKey = keyof ValidForm;

export interface NzColor extends Color {}