diff --git a/packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx b/packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx index bd43e86ae74..a15e07057af 100644 --- a/packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx +++ b/packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx @@ -1,4 +1,4 @@ -import React, { FC, useCallback, useEffect, useRef } from 'react'; +import React, { FC, RefCallback, useCallback, useEffect, useRef } from 'react'; import { isNil } from 'lodash'; import classNames from 'classnames'; import { css } from '@emotion/css'; @@ -16,6 +16,7 @@ interface Props { hideTracksWhenNotNeeded?: boolean; hideHorizontalTrack?: boolean; hideVerticalTrack?: boolean; + scrollRefCallback?: RefCallback; scrollTop?: number; setScrollTop?: (position: ScrollbarPosition) => void; autoHeightMin?: number | string; @@ -35,11 +36,17 @@ export const CustomScrollbar: FC = ({ hideTracksWhenNotNeeded = false, hideHorizontalTrack, hideVerticalTrack, + scrollRefCallback, updateAfterMountMs, scrollTop, children, }) => { - const ref = useRef(null); + const ref = useRef(null); + useEffect(() => { + if (ref.current) { + scrollRefCallback?.(ref.current.view); + } + }, [ref, scrollRefCallback]); const styles = useStyles2(getStyles); const updateScroll = () => { diff --git a/packages/grafana-ui/src/components/Select/SelectMenu.tsx b/packages/grafana-ui/src/components/Select/SelectMenu.tsx index 8dbe5df52a4..d32e53ccf6a 100644 --- a/packages/grafana-ui/src/components/Select/SelectMenu.tsx +++ b/packages/grafana-ui/src/components/Select/SelectMenu.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { FC, RefCallback } from 'react'; import { useTheme2 } from '../../themes/ThemeContext'; import { getSelectStyles } from './getSelectStyles'; import { cx } from '@emotion/css'; @@ -9,23 +9,22 @@ import { IconName } from '../../types'; interface SelectMenuProps { maxHeight: number; - innerRef: React.Ref; + innerRef: RefCallback; innerProps: {}; } -export const SelectMenu = React.forwardRef>((props, ref) => { +export const SelectMenu: FC = ({ children, maxHeight, innerRef, innerProps }) => { const theme = useTheme2(); const styles = getSelectStyles(theme); - const { children, maxHeight, innerRef, innerProps } = props; return ( -
- +
+ {children}
); -}); +}; SelectMenu.displayName = 'SelectMenu'; @@ -34,38 +33,44 @@ interface SelectMenuOptionProps { isFocused: boolean; isSelected: boolean; innerProps: any; + innerRef: RefCallback; renderOptionLabel?: (value: SelectableValue) => JSX.Element; data: SelectableValue; } -export const SelectMenuOptions = React.forwardRef>>( - (props, ref) => { - const theme = useTheme2(); - const styles = getSelectStyles(theme); - const { children, innerProps, data, renderOptionLabel, isSelected, isFocused } = props; +export const SelectMenuOptions: FC> = ({ + children, + data, + innerProps, + innerRef, + isFocused, + isSelected, + renderOptionLabel, +}) => { + const theme = useTheme2(); + const styles = getSelectStyles(theme); - return ( -
- {data.icon && } - {data.imgUrl && {data.label} -
- {renderOptionLabel ? renderOptionLabel(data) : children} - {data.description &&
{data.description}
} - {data.component && } -
+ return ( +
+ {data.icon && } + {data.imgUrl && {data.label} +
+ {renderOptionLabel ? renderOptionLabel(data) : children} + {data.description &&
{data.description}
} + {data.component && }
- ); - } -); +
+ ); +}; SelectMenuOptions.displayName = 'SelectMenuOptions';