Skip to content

Commit

Permalink
Stash value in localStorage for a better demo
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw authored Sep 30, 2023
1 parent 0ccf84b commit 4d96d30
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions templates/pages/tools/resizing-textarea.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ <h1>Single line auto-growing textarea</h1>
</pre>

<script>
// Just for the demo: stash textarea value in localStorage
const KEY = 'resizeTextareaContent';
const ta = document.querySelector('textarea');
function saveTextarea() {
localStorage.setItem(KEY, ta.value);
}
const saved = localStorage.getItem(KEY);
if (saved && !ta.value) {
ta.value = saved;
}
ta.addEventListener('input', saveTextarea);

// Trigger input on every textarea on the page, to trigger resize:
document.querySelectorAll('textarea').forEach(el => {
el.dispatchEvent(new Event('input', {
bubbles: true,
Expand Down

0 comments on commit 4d96d30

Please sign in to comment.