Issue
I'm using stencil.js to create a web component that is framework agnostic and contains some ionic4 web components including <ion-input>
The docs for ion-input
show a method getInputElement() => Promise<HTMLInputElement>
to access the native <input>
but I'm not finding the correct way to use it to expose the inner element in my component.
How does getInputElement
it get used?
@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: true
})
export class MyComponent {
@Element() el: HTMLElement;
@Prop .... ///some props
@State ... // some state
componentDidLoad(){}
render() (
<div className="foo">
<ion-item>
<ion-label> {this.someProp}</ion-label>
<ion-input
value={this.someProp}
clear-input={this.someProp}
onInput={this.handleInput} />
</ion-item>
<div>...more</div>
</div>
)
}
Solution
I'd assume you could do something like this using the ref
feature (you should probably type this):
ionInputElement;
@Element() el: HTMLElement;
@Prop .... ///some props
@State ... // some state
componentDidLoad(){
this.ionInputElement.getInputElement().then((el) => this.el = el);
}
render() {
return (
<div className="foo">
<ion-item>
<ion-label> {this.someProp}</ion-label>
<ion-input ref={(el) => this.ionInputElement = el}
value={this.someProp}
clear-input={this.someProp}
onInput={this.handleInput} />
</ion-item>
<div>...more</div>
</div>
);
}
Answered By - G. Tranter
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.