Skip to content

Create component where I'm interested in its value #2264

Answered by zandaqo
jkaan asked this question in Q&A
Discussion options

You must be logged in to vote
class PasswordField extends LitElement {
  value = '';
  static properties = {
    value: { type: String }
  }
  updateValue() {
    this.value = this.renderRoot?.querySelector('input')?.value || '';
  }
  render() {
    return html`<div class="container">
         <input type="password" .value=${this.value} @input=${this.updateValue} />
      </div>`;
  }
}

Now I'm interested in the value of the input type of the password-field, how would I go about getting that value out (possibly reactive so I can have the current value always up to date)?

const password = this.querySelector('password-field')?.value

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jkaan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants