From 77c36fa1228f5047e04c2b2f1238660a835627a8 Mon Sep 17 00:00:00 2001 From: Lukas Harbarth Date: Thu, 8 Oct 2026 09:10:31 +0200 Subject: [PATCH 1/2] feat(AnalyticalTable): allow disabling plugin-hooks --- .../docs/AnalyticalTableHooks.mdx | 21 +++ .../docs/PluginAnnounceEmptyCells.mdx | 2 + .../docs/PluginDisableRowSelection.mdx | 2 + .../AnalyticalTable/docs/PluginF2CellEdit.mdx | 2 + .../docs/PluginIndeterminateRowSelection.mdx | 2 + .../docs/PluginManualRowSelect.mdx | 2 + .../docs/PluginOnColumnResize.mdx | 1 + .../docs/PluginOrderedMultiSort.mdx | 2 + .../docs/PluginStickyColumns.mdx | 2 + .../pluginHooks/useAnnounceEmptyCells.ts | 56 +++++- .../pluginHooks/useF2CellEdit.ts | 55 +++++- .../useIndeterminateRowSelection.tsx | 30 +++- .../pluginHooks/useManualRowSelect.ts | 16 +- .../pluginHooks/useOnColumnResize.ts | 13 +- .../pluginHooks/useOrderedMultiSort.ts | 10 +- .../pluginHooks/useRowDisableSelection.tsx | 19 ++- .../pluginHooks/useStickyColumns.ts | 66 +++++--- .../test/PluginHooks.gallery.tsx | 160 ++++++++++++++++++ .../AnalyticalTable/test/PluginHooks.spec.tsx | 139 +++++++++++++++ .../components/AnalyticalTable/types/index.ts | 17 ++ 20 files changed, 564 insertions(+), 53 deletions(-) create mode 100644 packages/main/src/components/AnalyticalTable/test/PluginHooks.gallery.tsx create mode 100644 packages/main/src/components/AnalyticalTable/test/PluginHooks.spec.tsx diff --git a/packages/main/src/components/AnalyticalTable/docs/AnalyticalTableHooks.mdx b/packages/main/src/components/AnalyticalTable/docs/AnalyticalTableHooks.mdx index 0ceab668bee..07ca7058706 100644 --- a/packages/main/src/components/AnalyticalTable/docs/AnalyticalTableHooks.mdx +++ b/packages/main/src/components/AnalyticalTable/docs/AnalyticalTableHooks.mdx @@ -35,4 +35,25 @@ const tableHooks = [useAnnounceEmptyCells]; // this array should be memoized ``` +## Disabling a Plugin Hook + +Every plugin hook accepts a `disabled` option (default `false`). When `disabled` is `true`, the hook keeps its slot in the `tableHooks` array but does nothing. + +React's [rules of hooks](https://react.dev/reference/rules/rules-of-hooks) forbid adding or removing `tableHooks` entries at runtime, so use `disabled` to switch a hook off instead. To toggle it while the table is mounted, re-create the hook **at the same position** in the (memoized) `tableHooks` array with the new `disabled` value — never add, remove, or reorder entries, and keep `disabled` in the array's dependencies. + +The two hooks that are usually passed by reference (`useAnnounceEmptyCells`, `useF2CellEdit`) also accept the option when called as a factory. The call form depends on the hook's other parameters: + +```jsx +const tableHooks = useMemo( + () => [ + useAnnounceEmptyCells({ disabled }), // factory form of a by-reference hook + useStickyColumns({ disabled }), // options object + useManualRowSelect('isSelected', { disabled }), // positional arg + options + ], + [disabled], +); + +; +``` +