Skip to content

Commit

Permalink
fix(date-picker): corrige erro no console
Browse files Browse the repository at this point in the history
Corrige erro ao focar no botão e pressionar teclas diferentes de `enter` e `space`

DTHFUI-9908
  • Loading branch information
jcorrea97 authored and pedrodominguesp committed Nov 11, 2024
1 parent 2ba3ccb commit c70612a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions projects/ui/src/lib/components/po-field/po-input/po-mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,40 @@ describe('PoMask', () => {
expect(fakeThis.finalPosition).toBe(fakeThis.initialPosition);
});

it('resetPositions: should not call the function if the event does not have setSelectionRange', () => {
const mockEvent = {
target: {}
};

const fakeThis = mask;

expect(() => fakeThis.setPositions(mockEvent)).not.toThrow();
});

it('setSelectionRange: should not call the function if the event does not have setSelectionRange', () => {
const mockEvent = {
target: {}
};

const fakeThis = mask;
fakeThis.initialPosition = 2;
fakeThis.finalPosition = 1;

expect(() => fakeThis.setSelectionRange(mockEvent)).not.toThrow();
});

it('setSelectionRange: should not call the function if the event does not have setSelectionRange and final is larger than initial', () => {
const mockEvent = {
target: {}
};

const fakeThis = mask;
fakeThis.initialPosition = 1;
fakeThis.finalPosition = 2;

expect(() => fakeThis.setSelectionRange(mockEvent)).not.toThrow();
});

it('should change the positions with a defined value', () => {
const fakeThis = mask;
fakeThis.initialPosition = 3;
Expand Down
6 changes: 3 additions & 3 deletions projects/ui/src/lib/components/po-field/po-input/po-mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export class PoMask {

setSelectionRange($event: any) {
if (this.initialPosition > this.finalPosition) {
$event.target.setSelectionRange(this.finalPosition, this.initialPosition);
$event.target.setSelectionRange?.(this.finalPosition, this.initialPosition);
} else {
$event.target.setSelectionRange(this.initialPosition, this.finalPosition);
$event.target.setSelectionRange?.(this.initialPosition, this.finalPosition);
}
}

Expand Down Expand Up @@ -237,7 +237,7 @@ export class PoMask {

// posiciona o cursor de acordo com o controle de posição
setPositions($event: any) {
$event.target.setSelectionRange(this.initialPosition, this.finalPosition);
$event.target.setSelectionRange?.(this.initialPosition, this.finalPosition);
}

// muda a posição do cursor e atualiza o controle de posição
Expand Down

0 comments on commit c70612a

Please sign in to comment.