Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions core/src/components/textarea/test/basic/textarea.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@ import { configs, test } from '@utils/test/playwright';
*/
configs({ directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('textarea: basic'), () => {
// Regression coverage for https://github.com/ionic-team/ionic-framework/issues/31579
test('should place the caret at the end when focused with an initial value', async ({ page }) => {
await page.setContent(`<ion-textarea value="Hello world"></ion-textarea>`, config);

const textarea = page.locator('ion-textarea');
const nativeTextarea = textarea.locator('textarea');

await textarea.evaluate(async (el: HTMLIonTextareaElement) => {
await el.setFocus();
});

await expect(nativeTextarea).toBeFocused();
await expect
.poll(() => nativeTextarea.evaluate((el: HTMLTextAreaElement) => [el.selectionStart, el.selectionEnd]))
.toEqual([11, 11]);
});

test('should preserve an existing selection when an unrelated render occurs', async ({ page }) => {
await page.setContent(`<ion-textarea value="Hello world"></ion-textarea>`, config);

const textarea = page.locator('ion-textarea');
const nativeTextarea = textarea.locator('textarea');

await textarea.evaluate(async (el: HTMLIonTextareaElement) => {
await el.setFocus();
});
await nativeTextarea.evaluate((el: HTMLTextAreaElement) => el.setSelectionRange(1, 4));

await textarea.evaluate((el) => el.setAttribute('helper-text', 'Updated helper text'));
await page.waitForChanges();

await expect
.poll(() => nativeTextarea.evaluate((el: HTMLTextAreaElement) => [el.selectionStart, el.selectionEnd]))
.toEqual([1, 4]);
});

test('should stretch to fill height when min-height is set on the host', async ({ page }) => {
await page.setContent(
`
Expand Down
5 changes: 2 additions & 3 deletions core/src/components/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ export class Textarea implements ComponentInterface {
cols={this.cols}
rows={this.rows}
wrap={this.wrap}
value={value}
onInput={this.onInput}
onChange={this.onChange}
onBlur={this.onBlur}
Expand All @@ -812,9 +813,7 @@ export class Textarea implements ComponentInterface {
aria-describedby={this.getHintTextID()}
aria-invalid={this.isInvalid ? 'true' : undefined}
{...this.inheritedAttributes}
>
{value}
</textarea>
/>
</div>
</div>
<div class="textarea-end" ref={(el) => (this.endContainerEl = el)}>
Expand Down
Loading