From f0b601ba4583a0a4ebf4aed59a2b5bb3b22b7b7c Mon Sep 17 00:00:00 2001 From: Uyen Doan <56598021+smmr-dn@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:58:17 -0500 Subject: [PATCH] Added console warning for `Table` when both `subRows` and `subComponent` exist (#2288) --- .changeset/cuddly-gorillas-type.md | 5 +++++ packages/itwinui-react/src/core/Table/Table.tsx | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .changeset/cuddly-gorillas-type.md diff --git a/.changeset/cuddly-gorillas-type.md b/.changeset/cuddly-gorillas-type.md new file mode 100644 index 00000000000..3bfa4f4912c --- /dev/null +++ b/.changeset/cuddly-gorillas-type.md @@ -0,0 +1,5 @@ +--- +'@itwin/itwinui-react': patch +--- + +Added warning log in browser when both `subRows` and `subComponent` are passed into `Table`. diff --git a/packages/itwinui-react/src/core/Table/Table.tsx b/packages/itwinui-react/src/core/Table/Table.tsx index 8bbe3feb639..e48d97e53af 100644 --- a/packages/itwinui-react/src/core/Table/Table.tsx +++ b/packages/itwinui-react/src/core/Table/Table.tsx @@ -656,6 +656,16 @@ export const Table = < } } + if ( + process.env.NODE_ENV === 'development' && + subComponent && + data.some((item) => !!(item.subRows as T[] | undefined)?.length) + ) { + logWarning( + `Passing both \`subComponent\` and \`data\` with \`subRows\` is not supported. There are features designed for \`subRows\` that are not compatible with \`subComponent\` and vice versa.`, + ); + } + const ariaDataAttributes = Object.entries(rest).reduce( (result, [key, value]) => { if (key.startsWith('data-') || key.startsWith('aria-')) {