diff --git a/.betterer.results b/.betterer.results index a2718115ff9..3ec7a39139e 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1644,7 +1644,12 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "3"], [0, 0, 0, "Do not use any type assertions.", "4"], [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Do not use any type assertions.", "6"] + [0, 0, 0, "Do not use any type assertions.", "6"], + [0, 0, 0, "Do not use any type assertions.", "7"], + [0, 0, 0, "Do not use any type assertions.", "8"], + [0, 0, 0, "Do not use any type assertions.", "9"], + [0, 0, 0, "Do not use any type assertions.", "10"], + [0, 0, 0, "Do not use any type assertions.", "11"] ], "packages/grafana-ui/src/components/Table/TableCell.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], diff --git a/packages/grafana-ui/src/components/Table/Table.tsx b/packages/grafana-ui/src/components/Table/Table.tsx index 6b8e71a979c..d0faba48455 100644 --- a/packages/grafana-ui/src/components/Table/Table.tsx +++ b/packages/grafana-ui/src/components/Table/Table.tsx @@ -132,6 +132,8 @@ export const Table: FC = memo((props: Props) => { } = props; const listRef = useRef(null); + const tableDivRef = useRef(null); + const fixedSizeListScrollbarRef = useRef(null); const tableStyles = useStyles2(getTableStyles); const headerHeight = noHeader ? 0 : tableStyles.cellHeight; @@ -221,6 +223,29 @@ export const Table: FC = memo((props: Props) => { setPageSize(pageSize); }, [pageSize, setPageSize]); + useEffect(() => { + // To have the custom vertical scrollbar always visible (https://github.com/grafana/grafana/issues/52136), + // we need to bring the element from the FixedSizeList scope to the outer Table container scope, + // because the FixedSizeList scope has overflow. By moving scrollbar to container scope we will have + // it always visible since the entire width is in view. + + // Select the scrollbar element from the FixedSizeList scope + const listVerticalScrollbarHTML = (fixedSizeListScrollbarRef.current as HTMLDivElement)?.querySelector( + '.track-vertical' + ); + + // Select Table custom scrollbars + const tableScrollbarView = (tableDivRef.current as HTMLDivElement)?.firstChild; + + //If they exists, move the scrollbar element to the Table container scope + if (tableScrollbarView && listVerticalScrollbarHTML) { + listVerticalScrollbarHTML?.remove(); + (tableScrollbarView as HTMLDivElement).querySelector(':scope > .track-vertical')?.remove(); + + (tableScrollbarView as HTMLDivElement).append(listVerticalScrollbarHTML as Node); + } + }); + const RenderRow = React.useCallback( ({ index: rowIndex, style }) => { let row = rows[rowIndex]; @@ -291,21 +316,25 @@ export const Table: FC = memo((props: Props) => { }; return ( -
- +
+
{!noHeader && } {itemCount > 0 ? ( - - {RenderRow} - +
+ + + {RenderRow} + + +
) : (
No data