Skip to content

Commit

Permalink
Page: add scrollbar ID to use in image renderer (#88214)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgnesToulet authored May 24, 2024
1 parent 99b5259 commit f866157
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface Props {
autoHeightMin?: number | string;
updateAfterMountMs?: number;
onScroll?: React.UIEventHandler;
divId?: string;
}

/**
Expand All @@ -48,6 +49,7 @@ export const CustomScrollbar = ({
scrollTop,
onScroll,
children,
divId,
}: React.PropsWithChildren<Props>) => {
const ref = useRef<Scrollbars & { view: HTMLDivElement; update: () => void }>(null);
const styles = useStyles2(getStyles);
Expand Down Expand Up @@ -110,14 +112,17 @@ export const CustomScrollbar = ({
return <div {...passedProps} className="thumb-vertical" />;
}, []);

const renderView = useCallback((passedProps: JSX.IntrinsicElements['div']) => {
// fixes issues of visibility on safari and ios devices
if (passedProps.style && passedProps.style['WebkitOverflowScrolling'] === 'touch') {
passedProps.style['WebkitOverflowScrolling'] = 'auto';
}
const renderView = useCallback(
(passedProps: JSX.IntrinsicElements['div']) => {
// fixes issues of visibility on safari and ios devices
if (passedProps.style && passedProps.style['WebkitOverflowScrolling'] === 'touch') {
passedProps.style['WebkitOverflowScrolling'] = 'auto';
}

return <div {...passedProps} className="scrollbar-view" />;
}, []);
return <div {...passedProps} className="scrollbar-view" id={divId} />;
},
[divId]
);

const onScrollStop = useCallback(() => {
ref.current && setScrollTop && setScrollTop(ref.current.getValues());
Expand Down
4 changes: 2 additions & 2 deletions public/app/core/components/FlaggedScroller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function FlaggedScrollbar(props: FlaggedScrollerProps) {
}

// Shim to provide API-compatibility for Page's scroll-related props
function NativeScrollbar({ children, scrollRefCallback, scrollTop }: FlaggedScrollerProps) {
function NativeScrollbar({ children, scrollRefCallback, scrollTop, divId }: FlaggedScrollerProps) {
const styles = useStyles2(getStyles);
const ref = useRef<HTMLDivElement>(null);

Expand All @@ -33,7 +33,7 @@ function NativeScrollbar({ children, scrollRefCallback, scrollTop }: FlaggedScro

return (
// Set the .scrollbar-view class to help e2e tests find this, like in CustomScrollbar
<div ref={ref} className={cx(styles.nativeScrollbars, 'scrollbar-view')}>
<div ref={ref} className={cx(styles.nativeScrollbars, 'scrollbar-view')} id={divId}>
{children}
</div>
);
Expand Down
16 changes: 14 additions & 2 deletions public/app/core/components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ export const Page: PageType = ({
return (
<div className={cx(styles.wrapper, className)} {...otherProps}>
{layout === PageLayoutType.Standard && (
<FlaggedScrollbar autoHeightMin={'100%'} scrollTop={scrollTop} scrollRefCallback={scrollRef}>
<FlaggedScrollbar
// This id is used by the image renderer to scroll through the dashboard
divId="page-scrollbar"
autoHeightMin={'100%'}
scrollTop={scrollTop}
scrollRefCallback={scrollRef}
>
<div className={styles.pageInner}>
{pageHeaderNav && (
<PageHeader
Expand All @@ -72,7 +78,13 @@ export const Page: PageType = ({
)}

{layout === PageLayoutType.Canvas && (
<FlaggedScrollbar autoHeightMin={'100%'} scrollTop={scrollTop} scrollRefCallback={scrollRef}>
<FlaggedScrollbar
// This id is used by the image renderer to scroll through the dashboard
divId="page-scrollbar"
autoHeightMin={'100%'}
scrollTop={scrollTop}
scrollRefCallback={scrollRef}
>
<div className={styles.canvasContent}>{children}</div>
</FlaggedScrollbar>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export function DashboardSceneRenderer({ model }: SceneComponentProps<DashboardS
</div>
)}
<CustomScrollbar
// This id is used by the image renderer to scroll through the dashboard
divId="page-scrollbar"
autoHeightMin={'100%'}
className={styles.scrollbarContainer}
testId={selectors.pages.Dashboard.DashNav.scrollContainer}
Expand Down

0 comments on commit f866157

Please sign in to comment.