Fix orderbook centering
This commit is contained in:
parent
1407c9a460
commit
ca9501e3cc
@ -10,10 +10,13 @@ type ElementProps = {
|
||||
* Assumed that the two sides are the same height
|
||||
*/
|
||||
export const useCenterOrderbook = ({ marketId, orderbookRef }: ElementProps) => {
|
||||
const orderbookEl = orderbookRef.current;
|
||||
const { clientHeight, scrollHeight } = orderbookEl ?? {};
|
||||
const shouldScroll = !!scrollHeight && !!clientHeight && scrollHeight > clientHeight;
|
||||
|
||||
useEffect(() => {
|
||||
if (orderbookRef.current) {
|
||||
const { clientHeight, scrollHeight } = orderbookRef.current;
|
||||
orderbookRef.current.scrollTo({ top: (scrollHeight - clientHeight) / 2 });
|
||||
if (orderbookEl && shouldScroll) {
|
||||
orderbookEl.scrollTo({ top: (scrollHeight - clientHeight) / 2 });
|
||||
}
|
||||
}, [orderbookRef.current, marketId]);
|
||||
}, [clientHeight, shouldScroll, marketId]);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user