diff --git a/packages/gitbook/src/components/DocumentView/Table/StickyViewGrid.tsx b/packages/gitbook/src/components/DocumentView/Table/StickyViewGrid.tsx index 3bc974146..9560acd7e 100644 --- a/packages/gitbook/src/components/DocumentView/Table/StickyViewGrid.tsx +++ b/packages/gitbook/src/components/DocumentView/Table/StickyViewGrid.tsx @@ -13,10 +13,11 @@ interface StickyViewGridProps { export function StickyViewGrid({ className, header, children }: StickyViewGridProps) { const rootRef = useRef(null); + const stickyHeaderRef = useRef(null); const bodyScrollRef = useRef(null); const bodyTableRef = useRef(null); - const onStickyHeaderWheel = useCallback((event: React.WheelEvent) => { + const onStickyHeaderWheel = useCallback((event: WheelEvent) => { const bodyScrollElement = bodyScrollRef.current; if (!bodyScrollElement) { return; @@ -31,6 +32,19 @@ export function StickyViewGrid({ className, header, children }: StickyViewGridPr event.preventDefault(); }, []); + useEffect(() => { + const stickyHeaderElement = stickyHeaderRef.current; + if (!stickyHeaderElement) { + return; + } + + stickyHeaderElement.addEventListener('wheel', onStickyHeaderWheel, { passive: false }); + + return () => { + stickyHeaderElement.removeEventListener('wheel', onStickyHeaderWheel); + }; + }, [onStickyHeaderWheel]); + const syncStickyLayout = useCallback(() => { const rootElement = rootRef.current; const bodyScrollElement = bodyScrollRef.current; @@ -85,11 +99,11 @@ export function StickyViewGrid({ className, header, children }: StickyViewGridPr data-scrollable="false" >
) {
+ } > - + ); } @@ -82,7 +80,10 @@ export function Table(props: BlockProps) { 'w-full min-w-0 overflow-x-auto overflow-y-hidden border-tint-subtle' )} > - +
+ {withHeader ? : null} + +
); diff --git a/packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx b/packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx index dde835a60..7ba3620b7 100644 --- a/packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx +++ b/packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx @@ -7,9 +7,11 @@ import type { TableViewProps } from './Table'; import { getColumnWidth, getViewGridLayout } from './layout'; import { getColumnAlignment } from './utils'; -export function ViewGridHeader( - props: TableViewProps & { className?: string } -) { +interface ViewGridHeaderProps extends TableViewProps { + className?: string; +} + +export function ViewGridHeader(props: ViewGridHeaderProps) { const { block, view, context, className } = props; const { tableWidth, columnWidths, autoSizedColumns, fixedColumns } = getViewGridLayout({ block, @@ -61,13 +63,9 @@ export function ViewGridHeader( ); } -export interface ViewGridProps extends TableViewProps { - headerClassName?: string; -} - -export function ViewGrid(props: ViewGridProps) { - const { block, view, records, context, headerClassName } = props; - const { withHeader, tableWidth, autoSizedColumns, fixedColumns } = getViewGridLayout({ +export function ViewGrid(props: TableViewProps) { + const { block, view, records, context } = props; + const { tableWidth, autoSizedColumns, fixedColumns } = getViewGridLayout({ block, view, mode: context.mode, @@ -89,7 +87,6 @@ export function ViewGrid(props: ViewGridProps) { return (
- {withHeader ? : null} {body}
); diff --git a/packages/gitbook/src/components/DocumentView/Table/table.module.css b/packages/gitbook/src/components/DocumentView/Table/table.module.css index 6e61b1681..4b9908ab0 100644 --- a/packages/gitbook/src/components/DocumentView/Table/table.module.css +++ b/packages/gitbook/src/components/DocumentView/Table/table.module.css @@ -1,24 +1,7 @@ @reference "../../RootLayout/globals.css"; -/* Detect whether a scrollbar exists on the table */ -@keyframes detect-scroll { - from, - to { - --can-scroll: ; - } -} - -/* Apply styles to the Table if scrollbar exists */ .tableScrollArea { animation: detect-scroll linear; animation-timeline: scroll(self x); overscroll-behavior-x: none; - - --border-radius-if-can-scroll: var(--can-scroll) 0.375rem; - --border-radius-if-cant-scroll: 0; - border-radius: var(--border-radius-if-can-scroll, var(--border-radius-if-cant-scroll)); - - --border-width-if-can-scroll: var(--can-scroll) 1px; - --border-width-if-cant-scroll: 0; - border-width: var(--border-width-if-can-scroll, var(--border-width-if-cant-scroll)); }