icflorescu / icflorescu/mantine-datatable

`styles.table` prop fails to resolve functions or arrays

Open
#835 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.