stormid / components

UI components
https://stormid.github.io/components/
MIT License
2 stars 2 forks source link

Textarea > scroll change #240

Closed mjbp closed 3 weeks ago

mjbp commented 1 year ago

An issue observed when editing a tall textarea (>height of the viewport) is that the scroll position of the window changes during the period when the height is set to 'auto'.

One solution is to cache the scroll position of the window then restore it after the textarea height has been set, changing the update function:

const update = ({ target }) => {
    const scrollCache = window.scrollY;
    target.style.height = 'auto';
    target.style.height = `${target.scrollHeight}px`;
    window.scrollTo(0, scrollCache);
};