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 type when previous selection in input in some cases #5809
Conversation
Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.
PR Review ChecklistIf any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'. User Experience
Functionality
Maintainability
Quality
Internal
|
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
const curVal = $elements.getNativeProp(el, 'value') | ||
const bounds = $selection.getSelectionBounds(el) | ||
|
||
const potentialValue = $selection.insertSubstring(curVal + needsValue, key.text, [bounds.start + needsValueLength, bounds.end + needsValueLength]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i feel like this needs an explanation... its so opaque why this is necessary
e.currentTarget.select() | ||
}) | ||
|
||
// input[0].setSelectionRange(0,0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
packages/driver/src/dom/selection.ts
Outdated
return false | ||
} | ||
|
||
const getCaretPosition = function (el) { | ||
const bounds = getSelectionBounds(el) | ||
|
||
if (bounds.start == null) { | ||
if ((bounds.start == null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parenths
packages/driver/src/dom/selection.ts
Outdated
start: 0, | ||
end: 0, | ||
start: null, | ||
end: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch back to switch (true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor changes per my comments
packages/driver/src/dom/elements.ts
Outdated
const isAttrType = function (el: HTMLInputElement, type: string) { | ||
const elType = (el.getAttribute('type') || '').toLowerCase() | ||
|
||
if (elType === type) { | ||
return true | ||
} | ||
|
||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.should('have.value', '10') | ||
}) | ||
|
||
it('overwrites text when selectAll in focus handler in date', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email
not date
…ess-io#5809)" This reverts commit bfb9d83.
User facing changelog
.type
not respecting previous selection in non-selectionRange input element (email, number) (only way to change selection is with.select()
).type
not respecting previous selection if current value of the input is same as keyAdditional details
How has the user experience changed?
when attempting to use
.type
on a number or email input that has a text selection (or is selected in a focus handler):before (incorrect): text is appended to the current selection
after (correct): text replaces current selection
when attempting to use
.type
on an input that has a text selection (or is selected in a focus handler) of 1 character equal to the key typed:before (incorrect): ignores current key, next character replaces selection
after (correct): text replaces current selection, next character is typed after
PR Tasks