Skip to content

Commit

Permalink
feat(textarea): add autoGrow - set height to scrollHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlacombe committed Feb 6, 2019
1 parent ad0c8a4 commit f66c8d3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ export class IonText {
proxyInputs(IonText, ['color', 'mode']);

export declare interface IonTextarea extends StencilComponents<'IonTextarea'> {}
@Component({ selector: 'ion-textarea', changeDetection: 0, template: '<ng-content></ng-content>', inputs: ['mode', 'color', 'autocapitalize', 'autofocus', 'clearOnEdit', 'debounce', 'disabled', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly', 'required', 'spellcheck', 'cols', 'rows', 'wrap', 'value'] })
@Component({ selector: 'ion-textarea', changeDetection: 0, template: '<ng-content></ng-content>', inputs: ['mode', 'color', 'autocapitalize', 'autofocus', 'clearOnEdit', 'debounce', 'disabled', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly', 'required', 'spellcheck', 'cols', 'rows', 'wrap', 'autoGrow', 'value'] })
export class IonTextarea {
ionChange!: EventEmitter<CustomEvent>;
ionInput!: EventEmitter<CustomEvent>;
Expand All @@ -869,7 +869,7 @@ export class IonTextarea {
}
}
proxyMethods(IonTextarea, ['setFocus', 'getInputElement']);
proxyInputs(IonTextarea, ['mode', 'color', 'autocapitalize', 'autofocus', 'clearOnEdit', 'debounce', 'disabled', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly', 'required', 'spellcheck', 'cols', 'rows', 'wrap', 'value']);
proxyInputs(IonTextarea, ['mode', 'color', 'autocapitalize', 'autofocus', 'clearOnEdit', 'debounce', 'disabled', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly', 'required', 'spellcheck', 'cols', 'rows', 'wrap', 'autoGrow', 'value']);

export declare interface IonThumbnail extends StencilComponents<'IonThumbnail'> {}
@Component({ selector: 'ion-thumbnail', changeDetection: 0, template: '<ng-content></ng-content>' })
Expand Down
1 change: 1 addition & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ ion-text,prop,color,string | undefined,undefined,false,false
ion-text,prop,mode,"ios" | "md",undefined,false,false

ion-textarea,scoped
ion-textarea,prop,autoGrow,boolean,false,false,false
ion-textarea,prop,autocapitalize,string,'none',false,false
ion-textarea,prop,autofocus,boolean,false,false,false
ion-textarea,prop,clearOnEdit,boolean,false,false,false
Expand Down
8 changes: 8 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4514,6 +4514,10 @@ export namespace Components {
}

interface IonTextarea {
/**
* If `true`, the element height will increase based on the value.
*/
'autoGrow': boolean;
/**
* Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user.
*/
Expand Down Expand Up @@ -4596,6 +4600,10 @@ export namespace Components {
'wrap'?: 'hard' | 'soft' | 'off';
}
interface IonTextareaAttributes extends StencilHTMLAttributes {
/**
* If `true`, the element height will increase based on the value.
*/
'autoGrow'?: boolean;
/**
* Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user.
*/
Expand Down
1 change: 1 addition & 0 deletions core/src/components/textarea/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ The textarea component accepts the [native textarea attributes](https://develope

| Property | Attribute | Description | Type | Default |
| ---------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | -------------- |
| `autoGrow` | `auto-grow` | If `true`, the element height will increase based on the value. | `boolean` | `false` |
| `autocapitalize` | `autocapitalize` | Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user. | `string` | `'none'` |
| `autofocus` | `autofocus` | This Boolean attribute lets you specify that a form control should have input focus when the page loads. | `boolean` | `false` |
| `clearOnEdit` | `clear-on-edit` | If `true`, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types. | `boolean` | `false` |
Expand Down
7 changes: 7 additions & 0 deletions core/src/components/textarea/test/preview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
</ion-item>
</ion-list>

<div padding>
<ion-textarea placeholder="Auto Grow!" value="Height will increase as the user types...
Pretty cool!" auto-grow="true"></ion-textarea>
</div>

<div text-center>
<ion-button onclick="toggleBoolean('dynamicDisabled', 'disabled')">
Toggle Disabled
Expand Down
3 changes: 2 additions & 1 deletion core/src/components/textarea/test/standalone/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<ion-textarea placeholder="Textarea"></ion-textarea>
<ion-textarea value="value"></ion-textarea>
<ion-textarea value="44"></ion-textarea>
<ion-textarea placeholder="Custom" class="custom"></textarea>
<ion-textarea placeholder="Custom" class="custom"></ion-textarea>
<ion-textarea placeholder="Auto Grow!" auto-grow="true"></ion-textarea>

<style>
.custom {
Expand Down
14 changes: 14 additions & 0 deletions core/src/components/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export class Textarea implements ComponentInterface {
*/
@Prop() wrap?: 'hard' | 'soft' | 'off';

/**
* If `true`, the element height will increase based on the value.
*/
@Prop() autoGrow = false;

/**
* The value of the textarea.
*/
Expand All @@ -134,6 +139,7 @@ export class Textarea implements ComponentInterface {
if (nativeInput && nativeInput.value !== value) {
nativeInput.value = value;
}
this.runAutoGrow();
this.ionChange.emit({ value });
}

Expand Down Expand Up @@ -169,6 +175,14 @@ export class Textarea implements ComponentInterface {

componentDidLoad() {
this.debounceChanged();
this.runAutoGrow();
}

private runAutoGrow() {
if (this.nativeInput && this.autoGrow) {
this.nativeInput.style.height = '1px';
this.nativeInput.style.height = (4 + this.nativeInput.scrollHeight) + 'px';
}
}

/**
Expand Down

0 comments on commit f66c8d3

Please sign in to comment.