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

Datatable: Responsive broken in 7.2.0 #2594

Closed
melloware opened this issue Jan 20, 2022 · 4 comments · Fixed by #2595
Closed

Datatable: Responsive broken in 7.2.0 #2594

melloware opened this issue Jan 20, 2022 · 4 comments · Fixed by #2595
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@melloware
Copy link
Member

If you go to the Showcase Responsive demo in 7.1.0 it works properly when shrinking your browser. However in 7.2 all of the Responsive UI features seem broken.

https://www.primefaces.org/primereact-v7/#/datatable/responsive

You can see its not stacking and the whole site seems not to be respecting the media queries. This is happening in my local app too.

7.1.0 Correct
image

7.2.0 INCORRECT
image

@melloware melloware changed the title Responsive: Broken in 7.2.0 Datatable: Responsive broken in 7.2.0 Jan 20, 2022
@melloware
Copy link
Member Author

It looks like the dynamic inline styles are not being created...

@media screen and (max-width: 960px)
<style>
.p-datatable[pr_id_2] .p-datatable-tbody > tr > td {
    display: flex;
    width: 100% !important;
    align-items: center;
    justify-content: space-between;
}

@melloware
Copy link
Member Author

Broken by #2448

@FlipWarthog
Copy link
Contributor

FlipWarthog commented Jan 21, 2022

@melloware @mertsincan

I think the root issue is this change:

this.setState({ attributeSelector: UniqueComponentId() }, () => {
    this.el.setAttribute(this.state.attributeSelector, '');
});

if (this.props.responsiveLayout === 'stack' && !this.props.scrollable) {
    this.createResponsiveStyle();
}

attributeSelector is being set in the call to setState then this.createResponsiveStyle() attempts to use that state value, but (since state updates are async) the value doesn't exist yet.

I tested the following change against the latest showcase running locally and it seems to address the chicken/egg situation by creating the responsive style in the setState callback function.

this.setState({ attributeSelector: UniqueComponentId() }, () => {
    this.el.setAttribute(this.state.attributeSelector, '');

    if (this.props.responsiveLayout === 'stack' && !this.props.scrollable) {
        this.createResponsiveStyle();
    }
});

@melloware
Copy link
Member Author

melloware commented Jan 21, 2022

Nice analysis and fix!

@yigitfindikli yigitfindikli added this to the 7.2.1 milestone Feb 10, 2022
@yigitfindikli yigitfindikli added the Type: Bug Issue contains a defect related to a specific component. label Feb 10, 2022
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.

4 participants