Skip to content

Commit ed49f7e

Browse files
LFDanLudevongovettdannify
authored
Fix Firefox textarea autoscroll (#3432)
* make Textarea always scroll to bottom on height change this fixes issue where Firefox wouldnt auto scroll as the user typed in a quiet custom height textarea. The overflow style shifts cause the scroll position to remain static once we hit the user specified height * replace scrollTop solution with selectionRange instead scrollTop solution doesnt work if the user is in the middle of the textarea and starts deleting stuff since it will cause the scroll to jump to the bottom, this feels a bit gross because of the raf * adjusting approach back to scrollTop to avoid raf * simplifying logic * fixing FF autoscroll issue with scrollbar-width instead * fix tests * fix ssr tests * Apply review suggestion Co-authored-by: Devon Govett <[email protected]> * hack to fix Firefox autoscroll issue FF 104 introduces a bug where setting the input height directly doesnt actually change the height if overflow/scrollbar-width is reset. We decided to remove the overflow setting if we are in FF, note that this will bring the following bug back: #3379 (review) * adding filed brower bug Co-authored-by: Devon Govett <[email protected]> Co-authored-by: Danni <[email protected]>
1 parent d796e90 commit ed49f7e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/@react-spectrum/textfield/src/TextArea.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function TextArea(props: SpectrumTextFieldProps, ref: RefObject<TextFieldRef>) {
3131

3232
// not in stately because this is so we know when to re-measure, which is a spectrum design
3333
let [inputValue, setInputValue] = useControlledState(props.value, props.defaultValue, () => {});
34-
3534
let inputRef = useRef<HTMLTextAreaElement>();
3635

3736
let onHeightChange = useCallback(() => {
@@ -41,15 +40,21 @@ function TextArea(props: SpectrumTextFieldProps, ref: RefObject<TextFieldRef>) {
4140
let input = inputRef.current;
4241
let prevAlignment = input.style.alignSelf;
4342
let prevOverflow = input.style.overflow;
43+
// Firefox scroll position is lost when overflow: 'hidden' is applied so we skip applying it.
44+
// The measure/applied height is also incorrect/reset if we turn on and off
45+
// overflow: hidden in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1787062
46+
let isFirefox = 'MozAppearance' in input.style;
47+
if (!isFirefox) {
48+
input.style.overflow = 'hidden';
49+
}
4450
input.style.alignSelf = 'start';
45-
input.style.overflow = 'hidden';
4651
input.style.height = 'auto';
4752
// offsetHeight - clientHeight accounts for the border/padding.
4853
input.style.height = `${input.scrollHeight + (input.offsetHeight - input.clientHeight)}px`;
4954
input.style.overflow = prevOverflow;
5055
input.style.alignSelf = prevAlignment;
5156
}
52-
}, [isQuiet, inputRef]);
57+
}, [isQuiet, inputRef, props.height]);
5358

5459
useLayoutEffect(() => {
5560
if (inputRef.current) {

0 commit comments

Comments
 (0)