icflorescu / icflorescu/mantine-datatable
`styles.table` prop fails to resolve functions or arrays
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
The DataTable component features a styles prop that expects MantineStyleProp for keys root, table, header, footer, and pagination.
Mantine defines MantineStyleProp as follows:
type MantineStyle = CSSProperties | ((theme: MantineTheme) => CSSProperties);
type MantineStyleProp = MantineStyle | MantineStyle[] | MantineStyleProp[] | undefined;
As a result, it should accept functions receiving the Mantine theme, as well as arrays of CSSProperties or functions. However, passing a style function results in the styles not being applied, while passing an array throws the following runtime error:
TypeError: Failed to set an indexed property [0] on 'CSSStyleDeclaration': Indexed property setter is not supported.
To Reproduce
Minimal example passing a style function:
<DataTable
records={[{ id: 1 }]}
columns={[{ accessor: 'id' }]}
styles={{
table: () => ({
color: 'red',
}),
}}
/>
Minimal example passing an array:
<DataTable
records={[{ id: 1 }]}
columns={[{ accessor: 'id' }]}
styles={{
table: [{ color: 'red' }],
}}
/>
Expected behavior
In both cases, the text color should be red. When passing a function, the text remains black. When passing an array, the table fails to render and throws a TypeError.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the DataTable component's styles handling for the root, table, header, footer, and pagination keys, then reproduce the function and array examples from the issue. Confirm that both forms apply the red text color without the CSSStyleDeclaration TypeError, and add or update coverage for these cases if the project has relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100