Skip to content

Commit a7b646c

Browse files
authored
Wrap resize observer in animation frame
This will effectively debounce
1 parent c869f87 commit a7b646c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/vcf-date-range-picker.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,17 @@ import { afterNextRender } from '@polymer/polymer/lib/utils/render-status.js';
379379

380380
const wc = this;
381381
const resizeObserver = new ResizeObserver(entries => {
382-
for (let entry of entries) {
383-
if(entry.contentBoxSize) {
384-
var size = wc.shadowRoot.host.offsetWidth;
385-
wc._inputStartElement.shadowRoot.querySelector('[part="label"]')
386-
.setAttribute('style', "width: " + size + "px; max-width: max-content; overflow: hidden;");
387-
wc._inputStartElement.shadowRoot.querySelector('[part="error-message"]')
388-
.setAttribute('style', "width: " + size + "px; max-width: max-content; overflow: hidden;");
382+
requestAnimationFrame(() => {
383+
for (let entry of entries) {
384+
if(entry.contentBoxSize) {
385+
var size = wc.shadowRoot.host.offsetWidth;
386+
wc._inputStartElement.shadowRoot.querySelector('[part="label"]')
387+
.setAttribute('style', "width: " + size + "px; max-width: max-content; overflow: hidden;");
388+
wc._inputStartElement.shadowRoot.querySelector('[part="error-message"]')
389+
.setAttribute('style', "width: " + size + "px; max-width: max-content; overflow: hidden;");
390+
}
389391
}
390-
}
392+
});
391393
});
392394

393395
resizeObserver.observe(this);

0 commit comments

Comments
 (0)