Skip to content

Commit 6d4eabc

Browse files
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 <[email protected]>
1 parent 3086c9c commit 6d4eabc

10 files changed

+61
-2
lines changed

core/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ ion-textarea,prop,autocapitalize,string,'none',false,false
13641364
ion-textarea,prop,autofocus,boolean,false,false,false
13651365
ion-textarea,prop,clearOnEdit,boolean,false,false,false
13661366
ion-textarea,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
1367-
ion-textarea,prop,cols,number | undefined,undefined,false,false
1367+
ion-textarea,prop,cols,number | undefined,undefined,false,true
13681368
ion-textarea,prop,counter,boolean,false,false,false
13691369
ion-textarea,prop,counterFormatter,((inputLength: number, maxLength: number) => string) | undefined,undefined,false,false
13701370
ion-textarea,prop,debounce,number | undefined,undefined,false,false
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { expect } from '@playwright/test';
2+
import { configs, test } from '@utils/test/playwright';
3+
4+
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
5+
test.describe(title('textarea: cols'), () => {
6+
test('should respect cols when autogrow is not set', async ({ page }) => {
7+
await page.setContent(
8+
`
9+
<style>
10+
ion-textarea {
11+
border: 1px solid red;
12+
}
13+
</style>
14+
<div id="container" style="width: 300px; margin: 20px;">
15+
<ion-textarea label="Textarea" cols="5" value="Lorem Ipsum"></ion-textarea>
16+
</div>
17+
`,
18+
config
19+
);
20+
21+
const container = page.locator('#container');
22+
await expect(container).toHaveScreenshot(screenshot('textarea-cols'));
23+
});
24+
test('should ignore cols when autogrow is set', async ({ page }) => {
25+
await page.setContent(
26+
`
27+
<style>
28+
ion-textarea {
29+
border: 1px solid red;
30+
}
31+
</style>
32+
<div id="container" style="width: 300px; margin: 20px;">
33+
<ion-textarea label="Textarea" cols="5" auto-grow="true" value="Lorem Ipsum"></ion-textarea>
34+
</div>
35+
`,
36+
config
37+
);
38+
39+
const container = page.locator('#container');
40+
await expect(container).toHaveScreenshot(screenshot('textarea-cols-autogrow'));
41+
});
42+
});
43+
});

core/src/components/textarea/textarea.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@
6767
box-sizing: border-box;
6868
}
6969

70+
/**
71+
* When the cols property is set we should
72+
* respect that width instead of defaulting
73+
* to taking up the entire line.
74+
* Requires both the cols and autoGrow
75+
* properties to be reflected as attributes
76+
* on the host.
77+
*
78+
* cols does not work with autoGrow because
79+
* autoGrow would prevent line breaks from naturally
80+
* occurring until the textarea takes up the entire line width.
81+
*/
82+
:host([cols]:not([auto-grow])) {
83+
width: fit-content;
84+
}
85+
7086
// TODO: FW-2876 - Remove this selector
7187
:host(.legacy-textarea) {
7288
flex: 1;

core/src/components/textarea/textarea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class Textarea implements ComponentInterface {
180180
/**
181181
* The visible width of the text control, in average character widths. If it is specified, it must be a positive integer.
182182
*/
183-
@Prop() cols?: number;
183+
@Prop({ reflect: true }) cols?: number;
184184

185185
/**
186186
* The number of visible text lines for the control.

0 commit comments

Comments
 (0)