replaced document.getElementById with useRef

pull/1342/head
davidzagi93@gmail.com 3 years ago
parent 9858d12121
commit 58eaa2ddf4
  1. 12
      libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx

@ -64,6 +64,7 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
// terminal dragable // terminal dragable
const leftRef = useRef(null) const leftRef = useRef(null)
const panelRef = useRef(null)
const scrollToBottom = () => { const scrollToBottom = () => {
messagesEndRef.current.scrollIntoView({ behavior: 'smooth' }) messagesEndRef.current.scrollIntoView({ behavior: 'smooth' })
@ -297,15 +298,14 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
}) })
React.useEffect(() => { React.useEffect(() => {
const leftRef = document.getElementById('terminal-view') if (panelRef) {
if (leftRef) {
if (!leftHeight) { if (!leftHeight) {
setLeftHeight(leftRef.offsetHeight) setLeftHeight(panelRef.current.offsetHeight)
return return
} }
leftRef.style.height = `${leftHeight}px` panelRef.current.style.height = `${leftHeight}px`
} }
}, [leftHeight, setLeftHeight, inputEl]) }, [leftHeight, setLeftHeight, panelRef])
/* block contents that gets rendered from scriptRunner */ /* block contents that gets rendered from scriptRunner */
@ -438,7 +438,7 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
} }
return ( return (
<div style={{ height: '323px', flexGrow: 1 }} className='panel'> <div style={{ height: '323px', flexGrow: 1 }} className='panel' ref={panelRef}>
<div className="bar"> <div className="bar">
<div className="dragbarHorizontal" onMouseDown={mousedown} ref={leftRef}></div> <div className="dragbarHorizontal" onMouseDown={mousedown} ref={leftRef}></div>
<div className="menu border-top border-dark bg-light" data-id="terminalToggleMenu"> <div className="menu border-top border-dark bg-light" data-id="terminalToggleMenu">

Loading…
Cancel
Save