Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Table): a plugin's scroll-wrapper className reaches the scroll container (#10702)

Cindy Zhangc5ad42fe07a4
diff --git a/.changeset/table-scroll-wrapper-plugin-class.md b/.changeset/table-scroll-wrapper-plugin-class.md
new file mode 100644
index 0000000000..6722d44669
--- /dev/null
+++ b/.changeset/table-scroll-wrapper-plugin-class.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A Table plugin's `transformScrollWrapper` className now reaches the table's scroll container beside the wrapper's own class; before, the wrapper replaced it.
+
+@cixzhang
diff --git a/packages/core/src/Table/Table.test.tsx b/packages/core/src/Table/Table.test.tsx
index 89d225871c..f16e0625ab 100644
--- a/packages/core/src/Table/Table.test.tsx
+++ b/packages/core/src/Table/Table.test.tsx
@@ -1010,6 +1010,24 @@ describe('Table', () => {
expect(wrapper).toHaveAttribute('tabindex', '2');
});
+ it("composes a plugin's scroll-wrapper className with the wrapper's own", () => {
+ const plugin: TablePlugin<User> = {
+ transformScrollWrapper: props => ({
+ ...props,
+ htmlProps: {
+ ...props.htmlProps,
+ className: 'plugin-wrapper',
+ },
+ }),
+ };
+ render(<Table data={users} columns={columns} plugins={{custom: plugin}} />);
+ const wrapper = screen.getByRole('group', {name: 'Table'});
+ // The plugin's class reaches the scroll container, beside the wrapper's
+ // own theme target.
+ expect(wrapper).toHaveClass('plugin-wrapper');
+ expect(wrapper).toHaveClass('astryx-table-scroll-wrapper');
+ });
+
it('contains overscroll only while the table scrolls', () => {
const frames: FrameRequestCallback[] = [];
vi.stubGlobal(
diff --git a/packages/core/src/Table/Table.tsx b/packages/core/src/Table/Table.tsx
index 194ce4f3b3..a93ecef3d9 100644
--- a/packages/core/src/Table/Table.tsx
+++ b/packages/core/src/Table/Table.tsx
@@ -226,7 +226,13 @@ function TableScrollWrapper({
keyboardAccess: {owner: 'content'},
overscroll: 'contain',
});
- const {ref, ...restHtmlProps} = htmlProps ?? {};
+ // The spread below replaces className and style. Merge the plugin's instead.
+ const {
+ ref,
+ className: pluginClassName,
+ style: pluginStyle,
+ ...restHtmlProps
+ } = htmlProps ?? {};
const wrapperRef = useMemo(
() => mergeRefs(ref, runtime?.setViewport),
[ref, runtime?.setViewport],
@@ -256,6 +262,8 @@ function TableScrollWrapper({
hasBlockViewport && scrollWrapperStyles.viewport(viewportHeight),
...(pluginStyles ?? []),
),
+ pluginClassName,
+ pluginStyle,
),
});