Skip to content

Commit

Permalink
feat(input): add getInputElement() (#17183)
Browse files Browse the repository at this point in the history
expose internal <input> element

fixes #17174
  • Loading branch information
manucorporat authored Jan 21, 2019
1 parent cf9f53b commit a90084c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 3 deletions.
6 changes: 3 additions & 3 deletions angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export class IonInput {
proxyOutputs(this, this.el, ['ionInput', 'ionChange', 'ionBlur', 'ionFocus']);
}
}
proxyMethods(IonInput, ['setFocus']);
proxyMethods(IonInput, ['setFocus', 'getInputElement']);
proxyInputs(IonInput, ['color', 'mode', 'accept', 'autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'debounce', 'disabled', 'inputmode', 'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'spellcheck', 'step', 'size', 'type', 'value']);

export declare interface IonItem extends StencilComponents<'IonItem'> {}
Expand Down Expand Up @@ -689,7 +689,7 @@ export class IonSearchbar {
proxyOutputs(this, this.el, ['ionInput', 'ionChange', 'ionCancel', 'ionClear', 'ionBlur', 'ionFocus']);
}
}
proxyMethods(IonSearchbar, ['setFocus']);
proxyMethods(IonSearchbar, ['setFocus', 'getInputElement']);
proxyInputs(IonSearchbar, ['color', 'mode', 'animated', 'autocomplete', 'autocorrect', 'cancelButtonIcon', 'cancelButtonText', 'clearIcon', 'debounce', 'placeholder', 'searchIcon', 'showCancelButton', 'spellcheck', 'type', 'value']);

export declare interface IonSegment extends StencilComponents<'IonSegment'> {}
Expand Down Expand Up @@ -868,7 +868,7 @@ export class IonTextarea {
proxyOutputs(this, this.el, ['ionChange', 'ionInput', 'ionBlur', 'ionFocus']);
}
}
proxyMethods(IonTextarea, ['setFocus']);
proxyMethods(IonTextarea, ['setFocus', 'getInputElement']);
proxyInputs(IonTextarea, ['mode', 'color', 'autocapitalize', 'autofocus', 'clearOnEdit', 'debounce', 'disabled', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly', 'required', 'spellcheck', 'cols', 'rows', 'wrap', 'value']);

export declare interface IonThumbnail extends StencilComponents<'IonThumbnail'> {}
Expand Down
3 changes: 3 additions & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ ion-input,prop,spellcheck,boolean,false,false,false
ion-input,prop,step,string | undefined,undefined,false,false
ion-input,prop,type,"date" | "email" | "number" | "password" | "search" | "tel" | "text" | "time" | "url",'text',false,false
ion-input,prop,value,null | string | undefined,'',false,false
ion-input,method,getInputElement,getInputElement() => Promise<HTMLInputElement>
ion-input,method,setFocus,setFocus() => void
ion-input,event,ionBlur,void,true
ion-input,event,ionChange,InputChangeEventDetail,true
Expand Down Expand Up @@ -887,6 +888,7 @@ ion-searchbar,prop,showCancelButton,boolean,false,false,false
ion-searchbar,prop,spellcheck,boolean,false,false,false
ion-searchbar,prop,type,"email" | "number" | "password" | "search" | "tel" | "text" | "url",'search',false,false
ion-searchbar,prop,value,null | string | undefined,'',false,false
ion-searchbar,method,getInputElement,getInputElement() => Promise<HTMLInputElement>
ion-searchbar,method,setFocus,setFocus() => void
ion-searchbar,event,ionBlur,void,true
ion-searchbar,event,ionCancel,void,true
Expand Down Expand Up @@ -1091,6 +1093,7 @@ ion-textarea,prop,rows,number | undefined,undefined,false,false
ion-textarea,prop,spellcheck,boolean,false,false,false
ion-textarea,prop,value,null | string | undefined,'',false,false
ion-textarea,prop,wrap,"hard" | "off" | "soft" | undefined,undefined,false,false
ion-textarea,method,getInputElement,getInputElement() => Promise<HTMLTextAreaElement>
ion-textarea,method,setFocus,setFocus() => void
ion-textarea,event,ionBlur,void,true
ion-textarea,event,ionChange,TextareaChangeEventDetail,true
Expand Down
12 changes: 12 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,10 @@ export namespace Components {
*/
'disabled': boolean;
/**
* Returns the native `<input>` element used under the hood.
*/
'getInputElement': () => Promise<HTMLInputElement>;
/**
* A hint to the browser for which keyboard to display. This attribute applies when the value of the type attribute is `"text"`, `"password"`, `"email"`, or `"url"`. Possible values are: `"verbatim"`, `"latin"`, `"latin-name"`, `"latin-prose"`, `"full-width-latin"`, `"kana"`, `"katakana"`, `"numeric"`, `"tel"`, `"email"`, `"url"`.
*/
'inputmode'?: string;
Expand Down Expand Up @@ -3692,6 +3696,10 @@ export namespace Components {
*/
'debounce': number;
/**
* Returns the native `<input>` element used under the hood.
*/
'getInputElement': () => Promise<HTMLInputElement>;
/**
* The mode determines which platform styles to use.
*/
'mode': Mode;
Expand Down Expand Up @@ -4531,6 +4539,10 @@ export namespace Components {
*/
'disabled': boolean;
/**
* Returns the native `<textarea>` element used under the hood.
*/
'getInputElement': () => Promise<HTMLTextAreaElement>;
/**
* If the value of the type attribute is `text`, `email`, `search`, `password`, `tel`, or `url`, this attribute specifies the maximum number of characters that the user can enter.
*/
'maxlength'?: number;
Expand Down
8 changes: 8 additions & 0 deletions core/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ export class Input implements ComponentInterface {
}
}

/**
* Returns the native `<input>` element used under the hood.
*/
@Method()
getInputElement(): Promise<HTMLInputElement> {
return Promise.resolve(this.nativeInput!);
}

private getValue(): string {
return this.value || '';
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/components/input/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ It is meant for text `type` inputs only, such as `"text"`, `"password"`, `"email

## Methods

### `getInputElement() => Promise<HTMLInputElement>`

Returns the native `<input>` element used under the hood.

#### Returns

Type: `Promise<HTMLInputElement>`



### `setFocus() => void`

Sets focus on the specified `ion-input`. Use this method instead of the global
Expand Down
10 changes: 10 additions & 0 deletions core/src/components/searchbar/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ A Searchbar should be used instead of an input to search lists. A clear button i

## Methods

### `getInputElement() => Promise<HTMLInputElement>`

Returns the native `<input>` element used under the hood.

#### Returns

Type: `Promise<HTMLInputElement>`



### `setFocus() => void`

Sets focus on the specified `ion-searchbar`. Use this method instead of the global
Expand Down
8 changes: 8 additions & 0 deletions core/src/components/searchbar/searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ export class Searchbar implements ComponentInterface {
}
}

/**
* Returns the native `<input>` element used under the hood.
*/
@Method()
getInputElement(): Promise<HTMLInputElement> {
return Promise.resolve(this.nativeInput!);
}

/**
* Clears the input field and triggers the control change.
*/
Expand Down
10 changes: 10 additions & 0 deletions core/src/components/textarea/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ The textarea component accepts the [native textarea attributes](https://develope

## Methods

### `getInputElement() => Promise<HTMLTextAreaElement>`

Returns the native `<textarea>` element used under the hood.

#### Returns

Type: `Promise<HTMLTextAreaElement>`



### `setFocus() => void`

Sets focus on the specified `ion-textarea`. Use this method instead of the global
Expand Down
8 changes: 8 additions & 0 deletions core/src/components/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ export class Textarea implements ComponentInterface {
}
}

/**
* Returns the native `<textarea>` element used under the hood.
*/
@Method()
getInputElement(): Promise<HTMLTextAreaElement> {
return Promise.resolve(this.nativeInput!);
}

private emitStyle() {
this.ionStyle.emit({
'interactive': true,
Expand Down

0 comments on commit a90084c

Please sign in to comment.