Skip to content

Commit

Permalink
fix(ios, webviews): work-around selection on email inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed Mar 28, 2024
1 parent baa9d6b commit 509a34d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ extension WebCodeBuilder {
if (typeof element.setSelectionRange === 'function') {
const length = getLength(element);
/* This is a workaround. See: https://w3.org/Bugs/Public/show_bug.cgi?id=24796 */
const originalType = element.getAttribute('type');
element.setAttribute('type', 'text');
element.setSelectionRange(length, length);
element.setAttribute('type', originalType);
} else {
var range = element.ownerDocument.createRange();
Expand Down
8 changes: 8 additions & 0 deletions detox/test/e2e/29.webview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ describe('Web View', () => {
await expect(inputElement).toHaveText('Tester');
});

it('should type text in input with `email` type', async () => {
await inputElement.runScript((el) => { el.type = 'email'; });

await inputElement.typeText('Tester');

await expect(inputElement).toHaveText('Tester');
});

it('should keep cursor position on end while typing', async () => {
await inputElement.typeText('Test');
await expectWebViewToMatchSnapshot('typing-keep-cursor-position-webview-input-1');
Expand Down
2 changes: 1 addition & 1 deletion detox/test/src/Screens/WebViewScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const webViewFormWithScrolling = `
margin: 20px;
}
input[type=text] {
input[type=text], input[type=email] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
Expand Down

0 comments on commit 509a34d

Please sign in to comment.