Skip to content

Commit

Permalink
Prefer @query over ref() (matschik#175)
Browse files Browse the repository at this point in the history
* Prefer query over ref

Lit team prefers suggesting `@query` over `ref`. Though this example is simple enough to just do `this.renderRoot.querySelector('input')!.focus()` as well, the title for this section is "dom-ref"

* remove typescript syntax
  • Loading branch information
e111077 authored Sep 15, 2023
1 parent 6b8e5d3 commit 9c8091e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions content/2-templating/5-dom-ref/lit/input-focused.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { LitElement, html } from "lit";
import { customElement, state } from "lit/decorators.js";
import { ref, createRef } from "lit/directives/ref.js";
import { customElement, state, query } from "lit/decorators.js";

@customElement("input-focused")
export class InputFocused extends LitElement {
inputRef = createRef();
@query('input') inputEl;

firstUpdated() {
this.inputRef.value.focus();
this.inputEl.focus();
}

render() {
return html`<input type="text" ${ref(this.inputRef)} />`;
return html`<input type="text" />`;
}
}

0 comments on commit 9c8091e

Please sign in to comment.