fix(textarea): cols property is respected (#28081)

Issue number: resolves #22142

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Textarea always takes up the entire width of a line which prevents the
`cols` property from working correctly.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- The textarea respects the `col` property value only when `autoGrow` is
`false`

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.3.2-dev.11693402720.1adb3bcf`

---------

Co-authored-by: ionitron <hi@ionicframework.com>
This commit is contained in:
Liam DeBeasi
2023-09-01 10:56:41 -04:00
committed by GitHub
parent 3086c9c1ad
commit 6d4eabcc10
10 changed files with 61 additions and 2 deletions

View File

@ -1364,7 +1364,7 @@ ion-textarea,prop,autocapitalize,string,'none',false,false
ion-textarea,prop,autofocus,boolean,false,false,false ion-textarea,prop,autofocus,boolean,false,false,false
ion-textarea,prop,clearOnEdit,boolean,false,false,false ion-textarea,prop,clearOnEdit,boolean,false,false,false
ion-textarea,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true ion-textarea,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
ion-textarea,prop,cols,number | undefined,undefined,false,false ion-textarea,prop,cols,number | undefined,undefined,false,true
ion-textarea,prop,counter,boolean,false,false,false ion-textarea,prop,counter,boolean,false,false,false
ion-textarea,prop,counterFormatter,((inputLength: number, maxLength: number) => string) | undefined,undefined,false,false ion-textarea,prop,counterFormatter,((inputLength: number, maxLength: number) => string) | undefined,undefined,false,false
ion-textarea,prop,debounce,number | undefined,undefined,false,false ion-textarea,prop,debounce,number | undefined,undefined,false,false

View File

@ -0,0 +1,43 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('textarea: cols'), () => {
test('should respect cols when autogrow is not set', async ({ page }) => {
await page.setContent(
`
<style>
ion-textarea {
border: 1px solid red;
}
</style>
<div id="container" style="width: 300px; margin: 20px;">
<ion-textarea label="Textarea" cols="5" value="Lorem Ipsum"></ion-textarea>
</div>
`,
config
);
const container = page.locator('#container');
await expect(container).toHaveScreenshot(screenshot('textarea-cols'));
});
test('should ignore cols when autogrow is set', async ({ page }) => {
await page.setContent(
`
<style>
ion-textarea {
border: 1px solid red;
}
</style>
<div id="container" style="width: 300px; margin: 20px;">
<ion-textarea label="Textarea" cols="5" auto-grow="true" value="Lorem Ipsum"></ion-textarea>
</div>
`,
config
);
const container = page.locator('#container');
await expect(container).toHaveScreenshot(screenshot('textarea-cols-autogrow'));
});
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -67,6 +67,22 @@
box-sizing: border-box; box-sizing: border-box;
} }
/**
* When the cols property is set we should
* respect that width instead of defaulting
* to taking up the entire line.
* Requires both the cols and autoGrow
* properties to be reflected as attributes
* on the host.
*
* cols does not work with autoGrow because
* autoGrow would prevent line breaks from naturally
* occurring until the textarea takes up the entire line width.
*/
:host([cols]:not([auto-grow])) {
width: fit-content;
}
// TODO: FW-2876 - Remove this selector // TODO: FW-2876 - Remove this selector
:host(.legacy-textarea) { :host(.legacy-textarea) {
flex: 1; flex: 1;

View File

@ -180,7 +180,7 @@ export class Textarea implements ComponentInterface {
/** /**
* The visible width of the text control, in average character widths. If it is specified, it must be a positive integer. * The visible width of the text control, in average character widths. If it is specified, it must be a positive integer.
*/ */
@Prop() cols?: number; @Prop({ reflect: true }) cols?: number;
/** /**
* The number of visible text lines for the control. * The number of visible text lines for the control.