Skip to content

Commit

Permalink
fix(core): Time with [step] has unexpected cursor jump to the nex…
Browse files Browse the repository at this point in the history
…t segment on `ArrowUp`/`ArrowDown` (#1478)
  • Loading branch information
reverie3 authored Aug 22, 2024
1 parent ae7779f commit 59a5927
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Thumbs.db

# cypress
**/cypress/**/screenshots/**
projects/demo-integrations/cypress

.nx
.ssl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ export function guessValidValueByPattern(
const newValidatedChars = validatedCharacters + leadingCharacters;
const charConstraint = mask[newValidatedChars.length] || '';

if (isFixedCharacter(charConstraint)) {
return newValidatedChars + charConstraint;
}

if (!char.match(charConstraint)) {
return newValidatedChars;
}

if (maskedFrom === null && charIndex >= elementState.selection[0]) {
maskedFrom = newValidatedChars.length;
}
Expand All @@ -38,7 +30,13 @@ export function guessValidValueByPattern(
maskedTo = newValidatedChars.length;
}

return newValidatedChars + char;
if (isFixedCharacter(charConstraint)) {
return newValidatedChars + charConstraint;
}

return char.match(charConstraint)
? newValidatedChars + char
: newValidatedChars;
},
'',
);
Expand Down
52 changes: 48 additions & 4 deletions projects/demo-integrations/src/tests/kit/time/time-step.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ describe('Time', () => {
.should('have.a.prop', 'selectionEnd', 0)
.type('{rightArrow}')
.should('have.a.prop', 'selectionStart', 1)
.should('have.a.prop', 'selectionStart', 1)
.should('have.a.prop', 'selectionEnd', 1)
.type('{upArrow}')
.should('have.value', '13')
.should('have.a.prop', 'selectionStart', 1)
.should('have.a.prop', 'selectionStart', 1)
.should('have.a.prop', 'selectionEnd', 1)
.type('{rightArrow}')
.should('have.a.prop', 'selectionStart', 2)
.should('have.a.prop', 'selectionStart', 2)
.should('have.a.prop', 'selectionEnd', 2)
.type('{downArrow}')
.should('have.value', '12')
.should('have.a.prop', 'selectionStart', 2)
.should('have.a.prop', 'selectionStart', 2);
.should('have.a.prop', 'selectionEnd', 2);
});

it('type 12:{upArrow}{rightArrow}{downArrow}{rightArrow}{downArrow} => 12:59', () => {
Expand All @@ -79,6 +79,16 @@ describe('Time', () => {
.type('{rightArrow}{downArrow}'.repeat(2))
.should('have.value', '12:59');
});

it('12|:0 => {upArrow} => 13|:0', () => {
cy.get('@input')
.type('12:0')
.type('{leftArrow}'.repeat(2))
.type('{upArrow}')
.should('have.value', '13:0')
.should('have.a.prop', 'selectionStart', 2)
.should('have.a.prop', 'selectionEnd', 2);
});
});

describe('step = 0', () => {
Expand Down Expand Up @@ -107,6 +117,40 @@ describe('Time', () => {
});
});

describe('HH:MM:SS', () => {
describe('step = 1', () => {
beforeEach(() => {
cy.visit(`/${DemoPath.Time}/API?mode=HH:MM:SS&step=1`);
cy.get('#demo-content input')
.should('be.visible')
.first()
.focus()
.clear()
.as('input');
});

it('12|:0 => {upArrow} => 13|:0', () => {
cy.get('@input')
.type('12:0')
.type('{leftArrow}'.repeat(2))
.type('{upArrow}')
.should('have.value', '13:0')
.should('have.a.prop', 'selectionStart', 2)
.should('have.a.prop', 'selectionEnd', 2);
});

it('12:34|:5 => {downArrow} => 12:33|:5 ', () => {
cy.get('@input')
.type('12:34:5')
.type('{leftArrow}'.repeat(2))
.type('{downArrow}')
.should('have.value', '12:33:5')
.should('have.a.prop', 'selectionStart', 5)
.should('have.a.prop', 'selectionEnd', 5);
});
});
});

describe('HH:MM:SS.MSS', () => {
describe('step = 1', () => {
beforeEach(() => {
Expand Down

0 comments on commit 59a5927

Please sign in to comment.