1
0
Fork 0
forked from Mirrors/gomuks

web/composer: fix weird 1px scroll

This commit is contained in:
Tulir Asokan 2024-12-11 00:21:05 +02:00
parent 6d744d90ba
commit a1231c875b

View file

@ -374,11 +374,17 @@ const MessageComposer = () => {
// checking scrollHeight seems to be the only reliable way to get the size of the text. // checking scrollHeight seems to be the only reliable way to get the size of the text.
textInput.current.rows = 1 textInput.current.rows = 1
const newTextRows = Math.min((textInput.current.scrollHeight - 16) / 20, MAX_TEXTAREA_ROWS) const newTextRows = Math.min((textInput.current.scrollHeight - 16) / 20, MAX_TEXTAREA_ROWS)
if (newTextRows === MAX_TEXTAREA_ROWS) {
textInput.current.style.overflowY = "auto"
} else {
// There's a weird 1px scroll when using line-height, so set overflow to hidden when it's not needed
textInput.current.style.overflowY = "hidden"
}
textInput.current.rows = newTextRows textInput.current.rows = newTextRows
textRows.current = newTextRows textRows.current = newTextRows
// This has to be called unconditionally, because setting rows = 1 messes up the scroll state otherwise // This has to be called unconditionally, because setting rows = 1 messes up the scroll state otherwise
roomCtx.scrollToBottom() roomCtx.scrollToBottom()
}, [state, roomCtx]) }, [state.text, roomCtx])
// Saving to localStorage could be done in the reducer, but that's not very proper, so do it in an effect. // Saving to localStorage could be done in the reducer, but that's not very proper, so do it in an effect.
useEffect(() => { useEffect(() => {
roomCtx.isEditing.emit(editing !== null) roomCtx.isEditing.emit(editing !== null)