Skip to content

Commit 9fce828

Browse files
Fixing positional enter in text area. (#1614)
1 parent 82a6dea commit 9fce828

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/textinput/v1/textinput/clientlibs/site/js/textinputview.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@
8686
if (event.key === 'Enter') {
8787
// Prevent default action of Enter key to avoid form submission
8888
event.preventDefault();
89-
// Append a newline character to the widget value
90-
this.widget.value = this.widget.value + '\n';
89+
// Add a newline character to the widget value
90+
let cursorPosition = this.widget.selectionStart;
91+
let textBefore = this.widget.value.substring(0, cursorPosition);
92+
let textAfter = this.widget.value.substring(this.widget.selectionEnd);
93+
this.widget.value = textBefore + '\n' + textAfter;
94+
this.widget.selectionStart = this.widget.selectionEnd = cursorPosition + 1;
9195
}
9296
});
9397
}

ui.tests/test-module/specs/textinput/textinput.runtime.cy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ describe("Form Runtime with Text Input", () => {
148148
cy.get(`#${textmultiline}`).find("textarea").should('have.value', input);
149149
cy.get(`#${textmultiline}`).find("textarea").type('{enter}').type('multiline').blur().then(x => {
150150
cy.get(`#${textmultiline}`).find("textarea").should('have.value', "adobe\ntest\nmultiline");
151+
cy.get(`#${textmultiline}`).find("textarea").then($el => {
152+
const el = $el[0];
153+
el.setSelectionRange(1, 2); //selects the second character of value
154+
});
155+
cy.get(`#${textmultiline}`).find("textarea").type('{enter}').type('new line').blur().then(x => {
156+
cy.get(`#${textmultiline}`).find("textarea").should('have.value', "a\nnew lineobe\ntest\nmultiline");
157+
});
151158
});
152159
});
153160
})

0 commit comments

Comments
 (0)