packages/grafana-ui/src/components/ScrollContainer/ScrollContainer.mdx
import { Meta, Preview, ArgTypes } from '@storybook/addon-docs/blocks'; import { ScrollContainer } from './ScrollContainer';
<Meta title="MDX|ScrollContainer" component={ScrollContainer} />This component is used to create a scrollable container. It uses native scrollbars, has an option to show scroll indicators, and supports most Box properties.
ScrollContainer is intended to be a functionally equivalent replacement for CustomScrollbar. If you're not using any additional props in CustomScrollbar, it should be a drop-in replacement.
If you were using additional props, there are roughly 3 categories of changes:
autoHeightMin is now minHeightautoHeightMax is now maxHeightdivId is now idtestId is now data-testidscrollRefCallback is now refhideHorizontalTrack and hideVerticalTrack have been removed.
overflowX or overflowY to hidden. These names more closely match the CSS properties they represent.scrollTop and setScrollTop.
You can achieve the same behavior by using the ref prop to get a reference to the ScrollContainer component, and then calling scrollTo on that reference.
Before:
const [scrollTop, setScrollTop] = useState(0);
return <CustomScrollbar scrollTop={scrollTop}>// Your amazing scrolling content</CustomScrollbar>;
After:
const [scrollTop, setScrollTop] = useState(0);
const scrollRef = useRef<HTMLDivElement>(null);
useEffect(() => {
scrollRef.current?.scrollTo(0, scrollTop);
}, [scrollTop]);
return <ScrollContainer ref={scrollRef}>// Your amazing scrolling content</ScrollContainer>;
autoHide, autoHideTimeout and hideTracksWhenNotNeeded.
className
Box props, so everything should be available as a prop.updateAfterMountMs