Skip to content

Commit

Permalink
[lit-html] Allow undefined to be passed to the ref() directive (#3968)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfagnani committed Jun 22, 2023
1 parent dc974de commit 5bb4083
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/grumpy-stingrays-grab.md
@@ -0,0 +1,6 @@
---
'lit-html': patch
'lit': patch
---

Allow undefined to be passed to the ref() directive
2 changes: 1 addition & 1 deletion packages/lit-html/src/directives/ref.ts
Expand Up @@ -45,7 +45,7 @@ class RefDirective extends AsyncDirective {
private _ref?: RefOrCallback;
private _context?: object;

render(_ref: RefOrCallback) {
render(_ref?: RefOrCallback) {
return nothing;
}

Expand Down
7 changes: 7 additions & 0 deletions packages/lit-html/src/test/directives/ref_test.ts
Expand Up @@ -29,6 +29,13 @@ suite('ref', () => {
assert.equal(divRef, div);
});

test('handles an undefined ref', () => {
render(html`<div ${ref(undefined)}></div>`, container);
const div = container.firstElementChild;
// Not much to assert. We mainly care that we didn't throw
assert.isOk(div);
});

test('sets a ref when Ref object changes', () => {
const divRef1 = createRef();
const divRef2 = createRef();
Expand Down

0 comments on commit 5bb4083

Please sign in to comment.