Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Row component does not receive className and style property #7329

Closed
Nickog13 opened this issue Oct 11, 2024 · 6 comments · Fixed by #7360
Closed

Row component does not receive className and style property #7329

Nickog13 opened this issue Oct 11, 2024 · 6 comments · Fixed by #7360
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@Nickog13
Copy link
Contributor

Nickog13 commented Oct 11, 2024

Describe the bug

Hello,

it seems to me that this issue from 2 years ago is present again: #2693
I forked the CodeSandbox from the issue, updated primereact to the latest version and added classNames to both a Row and a Column component. While the column component sets the class, the row class stays unset. See Reproducer for an example. I was also able to reproduce it in another local project with a TreeTable as well.

Reproducer

https://codesandbox.io/p/sandbox/primereact-test-forked-7mt96v

System Information

npmPackages:
  primereact: ^10.8.3 => 10.8.3
  react: ^18.2.0 => 18.2.0

Steps to reproduce the behavior

Using a Row component with setting style or className results in a < tr > without style or className.

Expected behavior

The resulting < tr > component should get the style or the class set.

@Nickog13 Nickog13 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Oct 11, 2024
@melloware
Copy link
Member

@Nickog13 any analysis or PR would be great. I have a feeling the issue is somewhere merging the PassThrough props with the row props.

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Oct 11, 2024
@Nickog13
Copy link
Contributor Author

I think the issue is, the row props are not applied to the rows in components like datatable\TableFooter, datatable\TableHeader and the corresponding treetable components. For example in TableFooter.js there is createContent with that (in rows.map()):

const rootProps = mergeProps(
    {
        role: 'row'
    },
    getRowPTOptions(row, 'root')
);

Are the style and className property supposed to be included in getRowPTOptions(row, 'root')? I was able to fix it and include the className by using the RowBase.getProps() just like it is done in row\Row.js but I am unsure whether this is the correct way to fix it or to adjust getRowPTOptions:

const rowProps = RowBase.getProps(row.props, context);
const rootProps = mergeProps(
    {
        role: 'row'
    },
    rowProps,
    getRowPTOptions(row, 'root')
);

Also I am not sure at which points I need to fix this additionally, I guess TableFooter.js, TableHeader.js, TreeTableFooter.js, TreeTableHeader.js, but I am not sure if there are other components, at which needs to be fixed as well.

@melloware
Copy link
Member

Hmm the getRowPTOptions should already have the rowProps. Maybe that is where the issue is?

Nickog13 added a commit to Nickog13/primereact that referenced this issue Oct 19, 2024
@Nickog13
Copy link
Contributor Author

Nickog13 commented Oct 19, 2024

I have opened a PR with currently adding the RowBase.getProps() (have not seen your comment unfortunately). If getRowPTOptions should include it already, I can check further where the style and className are lost.

By the way, I needed to adjust a few ts interfaces by adding onToggle to Omit due to getting a build error (mentioned it in the PR). Is this currently present in the master code base? Error looks like this: "Type 'ToggleEvent is missing the following properties from type 'FieldSetToggleEvent': originalEvent, value". Just added it to Omit for now to be able to build it

@melloware melloware modified the milestones: 10.8.4, 10.8.5 Oct 19, 2024
@Nickog13
Copy link
Contributor Author

I think something is lost in ComponentBase getPTValue().
getRowPTOptions calls ptm() & ptmo() on the rProps which then both call getPTValue but this returns an undefined value.

I am not sure which part inside of the getPTValue() should contain the corresponding props, I see in the final return of the function that mergeSections is true and useMergeProps is false, so this line is used for the return:

: { ...globalPT, ...self, ...(Object.keys(datasetProps).length ? datasetProps : {}) }

with globalPT and self being undefined again.

Should self contain the rowProps or another variable? And should the row properties be returned in the ptm() or the ptmo() call?

@Nickog13
Copy link
Contributor Author

Nickog13 commented Nov 5, 2024

I assume, self should contain the corresponding props, however, it is undefined. Especially in ComponentBase getPTClassValue() I see that const value = getOptionValue(...args); gives an undefined value. So I think somethink goes wrong in getOptionValue(...args). I see that getOptionValue searches for a key in the obj, this key is always set to "root" but the underlying obj looks like this.

image

Why is the key actually set to 'root'?
Shouldn't the getOptionValue call for the getPTClassValue search for the "className" in obj?

melloware pushed a commit to Nickog13/primereact that referenced this issue Nov 5, 2024
melloware pushed a commit that referenced this issue Nov 5, 2024
* Fix for #7329

* Fix const variables to let where required for build

* Reset line changed by accident

* Fixed build issues Types of property 'onToggle' are incompatible by adding to Omit

* Reverted changes due to build issues with next version mismatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants