Skip to content

Commit fbb61b8

Browse files
mateusjmafjhonyeduardo
authored andcommitted
fix(datepicker): corrige foco no campo após selecionar data no mobile
Agora o componente passa a verificar se é um dispositivo móvel após a data ser selecionada no modo mobile, fazendo apenas com que o overlay do calendário seja fechado. Fixes DTHFUI-1495
1 parent 68558f9 commit fbb61b8

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -712,25 +712,46 @@ describe('PoDatepickerComponent:', () => {
712712
expect(component.formatToDate).not.toHaveBeenCalled();
713713
});
714714

715-
it('dateSelected: should set `calendar.visible` to false', () => {
716-
component.calendar.visible = true;
715+
describe('dateSelected:', () => {
717716

718-
spyOn(component, <any>'closeCalendar');
717+
it('should set `calendar.visible` to false', () => {
718+
component.calendar.visible = true;
719719

720-
component.dateSelected();
720+
spyOn(component, <any>'closeCalendar');
721721

722-
expect(component['closeCalendar']).toHaveBeenCalled();
723-
});
722+
component.dateSelected();
724723

725-
it('dateSelected: should call `controlModel` and `controlChangeEmitter`', () => {
724+
expect(component['closeCalendar']).toHaveBeenCalled();
725+
});
726726

727-
spyOn(component, 'controlModel');
728-
spyOn(component, <any>'controlChangeEmitter');
727+
it('should call `controlModel` and `controlChangeEmitter`', () => {
728+
spyOn(component, 'controlModel');
729+
spyOn(component, <any>'controlChangeEmitter');
729730

730-
component.dateSelected();
731+
component.dateSelected();
732+
733+
expect(component.controlModel).toHaveBeenCalled();
734+
expect(component['controlChangeEmitter']).toHaveBeenCalled();
735+
});
736+
737+
it('should call ´focus´ if ´verifyMobile´ returns ´false´.', () => {
738+
spyOn(component, 'verifyMobile').and.returnValue(<any> false);
739+
const spyInputFocus = spyOn(component.inputEl.nativeElement, 'focus');
740+
741+
component.dateSelected();
742+
743+
expect(spyInputFocus).toHaveBeenCalled();
744+
});
745+
746+
it('shouldn´t call ´focus´ if ´verifyMobile´ returns ´true´.', () => {
747+
spyOn(component, 'verifyMobile').and.returnValue(<any> true);
748+
const spyInputFocus = spyOn(component.inputEl.nativeElement, 'focus');
749+
750+
component.dateSelected();
751+
752+
expect(spyInputFocus).not.toHaveBeenCalled();
753+
});
731754

732-
expect(component.controlModel).toHaveBeenCalled();
733-
expect(component['controlChangeEmitter']).toHaveBeenCalled();
734755
});
735756

736757
it('formatToDate: should call `formatYear` with date year', () => {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ export class PoDatepickerComponent extends PoDatepickerBaseComponent implements
121121
}
122122

123123
dateSelected() {
124-
this.inputEl.nativeElement.focus();
124+
if (!this.verifyMobile()) {
125+
this.inputEl.nativeElement.focus();
126+
}
127+
125128
this.inputEl.nativeElement.value = this.formatToDate(this.date);
126129
this.controlModel(this.date);
127130
this.controlChangeEmitter();

0 commit comments

Comments
 (0)