You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2026/08/06 22:40:51 UTC

(superset) branch master updated: fix(plugin-chart-table): align sticky header column dividers with table body (#42573)

This is an automated email from the ASF dual-hosted git repository.

sadpandajoe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new ae66b697e5c fix(plugin-chart-table): align sticky header column dividers with table body (#42573)
ae66b697e5c is described below

commit ae66b697e5c682e4aaf886e9017923408aacb72a
Author: Joe Li <jo...@preset.io>
AuthorDate: Thu Aug 6 15:40:44 2026 -0700

    fix(plugin-chart-table): align sticky header column dividers with table body (#42573)
    
    Co-authored-by: Juliann Forbes <ju...@preset.io>
---
 .../src/DataTable/hooks/useSticky.tsx              | 11 ++--
 .../src/DataTable/utils/getScrollBarSize.ts        | 73 ++++++++++++++++------
 .../test/DataTable/utils/getScrollBarSize.test.ts  | 52 +++++++++++++++
 3 files changed, 114 insertions(+), 22 deletions(-)

diff --git a/superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx b/superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx
index 01e2c31f598..65231bc652d 100644
--- a/superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx
+++ b/superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx
@@ -31,7 +31,10 @@ import {
 } from 'react';
 import { TableInstance, Hooks } from 'react-table';
 import { useTheme, css } from '@apache-superset/core/theme';
-import getScrollBarSize from '../utils/getScrollBarSize';
+import {
+  CUSTOM_SCROLLBAR_SIZE,
+  getCustomScrollBarSize,
+} from '../utils/getScrollBarSize';
 import needScrollBar from '../utils/needScrollBar';
 import useMountedMemo from '../utils/useMountedMemo';
 
@@ -165,7 +168,7 @@ function StickyWrap({
   const scrollFooterRef = useRef<HTMLDivElement>(null); // fixed footer
   const scrollBodyRef = useRef<HTMLDivElement>(null); // main body
 
-  const scrollBarSize = getScrollBarSize();
+  const scrollBarSize = getCustomScrollBarSize();
   const { bodyHeight, columnWidths, hasVerticalScroll } = sticky;
   const needSizer =
     !columnWidths ||
@@ -226,8 +229,8 @@ function StickyWrap({
 
   const scrollBarStyles = css`
     &::-webkit-scrollbar {
-      width: 8px;
-      height: 8px;
+      width: ${CUSTOM_SCROLLBAR_SIZE}px;
+      height: ${CUSTOM_SCROLLBAR_SIZE}px;
     }
     &::-webkit-scrollbar-track {
       background: ${theme.colorFillQuaternary};
diff --git a/superset-frontend/plugins/plugin-chart-table/src/DataTable/utils/getScrollBarSize.ts b/superset-frontend/plugins/plugin-chart-table/src/DataTable/utils/getScrollBarSize.ts
index 5d86598bf21..0a5201f2097 100644
--- a/superset-frontend/plugins/plugin-chart-table/src/DataTable/utils/getScrollBarSize.ts
+++ b/superset-frontend/plugins/plugin-chart-table/src/DataTable/utils/getScrollBarSize.ts
@@ -16,33 +16,70 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+// Width/height of the custom `::-webkit-scrollbar` applied to the sticky
+// body and header sizer in useSticky.tsx.
+export const CUSTOM_SCROLLBAR_SIZE = 8;
+
 let cached: number | undefined;
+let cachedCustom: number | undefined;
 
 const css = (x: TemplateStringsArray) => x.join('\n');
 
+function measureScrollBarSize(probeClassName?: string) {
+  const inner = document.createElement('div');
+  const outer = document.createElement('div');
+  // Custom scrollbars are only styleable via a stylesheet rule, since
+  // inline styles can't express `::-webkit-scrollbar` pseudo-elements.
+  const style = probeClassName ? document.createElement('style') : undefined;
+  if (style && probeClassName) {
+    style.textContent = `.${probeClassName}::-webkit-scrollbar { width: ${CUSTOM_SCROLLBAR_SIZE}px; height: ${CUSTOM_SCROLLBAR_SIZE}px; }`;
+    inner.className = probeClassName;
+    document.head.append(style);
+  }
+  inner.style.cssText = css`
+    width: auto;
+    height: 100%;
+    overflow: scroll;
+  `;
+  outer.style.cssText = css`
+    position: absolute;
+    visibility: hidden;
+    overflow: hidden;
+    width: 100px;
+    height: 50px;
+  `;
+  outer.append(inner);
+  document.body.append(outer);
+  const size = outer.clientWidth - inner.clientWidth;
+  outer.remove();
+  style?.remove();
+  return size;
+}
+
+// Measures the browser/OS native scrollbar width. Used anywhere an
+// un-styled scrollable region's real footprint matters (e.g. the chart's
+// outer resize-twitch guard in TableChart.tsx).
 export default function getScrollBarSize(forceRefresh = false) {
   if (typeof document === 'undefined') {
     return 0;
   }
   if (cached === undefined || forceRefresh) {
-    const inner = document.createElement('div');
-    const outer = document.createElement('div');
-    inner.style.cssText = css`
-      width: auto;
-      height: 100%;
-      overflow: scroll;
-    `;
-    outer.style.cssText = css`
-      position: absolute;
-      visibility: hidden;
-      overflow: hidden;
-      width: 100px;
-      height: 50px;
-    `;
-    outer.append(inner);
-    document.body.append(outer);
-    cached = outer.clientWidth - inner.clientWidth;
-    outer.remove();
+    cached = measureScrollBarSize();
   }
   return cached;
 }
+
+// Measures the scrollbar width as it actually renders with the custom
+// `::-webkit-scrollbar` styling applied (see scrollBarStyles in
+// useSticky.tsx). On browsers that don't support `::-webkit-scrollbar`
+// (e.g. Firefox) this equals the native scrollbar width. Only use this for
+// elements that carry that same custom styling.
+export function getCustomScrollBarSize(forceRefresh = false) {
+  if (typeof document === 'undefined') {
+    return 0;
+  }
+  if (cachedCustom === undefined || forceRefresh) {
+    cachedCustom = measureScrollBarSize('superset-scrollbar-size-probe');
+  }
+  return cachedCustom;
+}
diff --git a/superset-frontend/plugins/plugin-chart-table/test/DataTable/utils/getScrollBarSize.test.ts b/superset-frontend/plugins/plugin-chart-table/test/DataTable/utils/getScrollBarSize.test.ts
new file mode 100644
index 00000000000..7ad2d83b800
--- /dev/null
+++ b/superset-frontend/plugins/plugin-chart-table/test/DataTable/utils/getScrollBarSize.test.ts
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import getScrollBarSize, {
+  CUSTOM_SCROLLBAR_SIZE,
+  getCustomScrollBarSize,
+} from '../../../src/DataTable/utils/getScrollBarSize';
+
+test('getScrollBarSize measures the native scrollbar without any custom styling probe', () => {
+  const appendSpy = jest.spyOn(document.head, 'append');
+
+  getScrollBarSize(true);
+
+  expect(appendSpy).not.toHaveBeenCalled();
+
+  appendSpy.mockRestore();
+});
+
+test('getCustomScrollBarSize measures the probe using the shared custom scrollbar size', () => {
+  const appendSpy = jest.spyOn(document.head, 'append');
+
+  getCustomScrollBarSize(true);
+
+  const styleEl = appendSpy.mock.calls
+    .map(args => args[0])
+    .find((node): node is HTMLStyleElement => node instanceof HTMLStyleElement);
+  expect(styleEl?.textContent).toContain(`width: ${CUSTOM_SCROLLBAR_SIZE}px`);
+
+  appendSpy.mockRestore();
+});
+
+test('CUSTOM_SCROLLBAR_SIZE matches the custom scrollbar width rendered in the sticky table', () => {
+  // useSticky.tsx's scrollBarStyles must stay in sync with this constant so
+  // the sticky header's shrink amount always matches the body's real
+  // scrollbar width.
+  expect(CUSTOM_SCROLLBAR_SIZE).toBe(8);
+});