/ Gists / Alpine js - directive (example)
On gists

Alpine js - directive (example)

Alpine.js

example.js Raw #

//  https://github.com/markmead/alpinejs-textarea-autogrow

export default function (Alpine) {
  Alpine.directive('grow', (el) => {
    el.addEventListener('input', () => {
      el.style.height = 'auto'

      el.style.height = `${el.scrollHeight}px`
    })
  })
}

inde.html Raw #

<textarea x-data x-grow></textarea>