Skip to content

Commit 5473d66

Browse files
committedOct 26, 2023
fix(dynamic-form): ajusta evento validate com método clean
O evento `validate` apenas é disparado se o usuário tocar no campo antes de clicar no `X` do `clean`. Foi feito um ajuste para que o evento `validate` seja disparado mesmo se o usuário clicar diretamente no `X` do `clean` sem tocar no campo. Fixes po-ui#1837
1 parent f92633d commit 5473d66

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed
 

‎projects/ui/src/lib/components/po-field/po-clean/po-clean-base.component.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { PoCleanBaseComponent } from './po-clean-base.component';
44

55
@Directive()
66
class PoClean extends PoCleanBaseComponent {
7+
focus(): void {}
8+
9+
blur(): void {}
10+
711
setInputValue(value: string): void {}
812

913
getInputValue(): string {

‎projects/ui/src/lib/components/po-field/po-clean/po-clean-base.component.ts

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export abstract class PoCleanBaseComponent {
2929
@Output('p-change-event') changeEvent: EventEmitter<any> = new EventEmitter<any>();
3030

3131
clear() {
32+
this.focus();
33+
this.blur();
3234
this.setInputValue(this.defaultValue);
3335
this.changeEvent.emit(this.defaultValue);
3436
}
@@ -37,6 +39,10 @@ export abstract class PoCleanBaseComponent {
3739
return this.defaultValue !== this.getInputValue();
3840
}
3941

42+
abstract focus(): void;
43+
44+
abstract blur(): void;
45+
4046
abstract setInputValue(value: string): void;
4147

4248
abstract getInputValue(): string;

‎projects/ui/src/lib/components/po-field/po-clean/po-clean.component.spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,34 @@ describe('PoCleanComponent', () => {
3030
expect(fixture.nativeElement.querySelector('.po-icon.po-field-icon.po-icon-close')).toBeDefined();
3131
});
3232

33+
it('focus: should call `focus` of input', () => {
34+
component.inputRef = {
35+
nativeElement: {
36+
focus: () => {}
37+
}
38+
};
39+
40+
spyOn(component.inputRef.nativeElement, 'focus');
41+
42+
component.focus();
43+
44+
expect(component.inputRef.nativeElement.focus).toHaveBeenCalled();
45+
});
46+
47+
it('focus: should call `blur` of input', () => {
48+
component.inputRef = {
49+
nativeElement: {
50+
blur: () => {}
51+
}
52+
};
53+
54+
spyOn(component.inputRef.nativeElement, 'blur');
55+
56+
component.blur();
57+
58+
expect(component.inputRef.nativeElement.blur).toHaveBeenCalled();
59+
});
60+
3361
it('should set value to input', () => {
3462
const fakeThis = {
3563
inputRef: {

‎projects/ui/src/lib/components/po-field/po-clean/po-clean.component.ts

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ import { PoCleanBaseComponent } from './po-clean-base.component';
1919
templateUrl: './po-clean.component.html'
2020
})
2121
export class PoCleanComponent extends PoCleanBaseComponent {
22+
focus() {
23+
this.inputRef.nativeElement.focus();
24+
}
25+
26+
blur() {
27+
this.inputRef.nativeElement.blur();
28+
}
29+
2230
setInputValue(value?: string) {
2331
if (this.inputRef && this.inputRef.nativeElement) {
2432
this.inputRef.nativeElement.value = value;

0 commit comments

Comments
 (0)
Please sign in to comment.