fix: center empty-content slot vertically and horizontally#691
Conversation
24c9557 to
02d195f
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces CSS changes to center the empty content message within the ngx-datatable body and updates the basic empty template example to include a fixed height and vertical scrollbar. The reviewer suggested refining the CSS to handle horizontal scrolling and white-space inheritance to ensure the centering logic works reliably across different configurations, while also noting browser compatibility considerations for the :has() pseudo-class.
There was a problem hiding this comment.
Pull request overview
Centers the datatable’s empty state content by applying flex layout to the body scroller when rendering the empty-content slot, and updates the empty-template demo to better showcase the behavior within a fixed-height, vertically scrollable table.
Changes:
- Add a
:has([empty-content])CSS rule ondatatable-scrollerto center empty content vertically and horizontally. - Update the empty-template demo to enable vertical scrolling and set a fixed height.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/app/basic/empty-template.component.ts | Adjusts the demo table height and enables vertical scrolling to demonstrate centering. |
| projects/ngx-datatable/src/lib/components/body/body.component.scss | Adds a :has([empty-content]) rule to flex-center projected empty content inside the scroller. |
Comments suppressed due to low confidence (1)
projects/ngx-datatable/src/lib/components/body/body.component.scss:25
- This rule sets
display: flexondatatable-scrollerto vertically center its children. However,datatable-scrollermay have an inlineheightset via[scrollHeight](e.g., virtualization/external virtual scrolling), which can be much larger than the viewport. In that case, centering occurs within the large scroller height and can push the empty content far out of view at scrollTop=0. Consider centering relative to the body viewport instead (e.g., apply flex styles to the scroll container for the empty state, or avoid applying centering whenscrollHeightis set).
&:has([empty-content]) {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0aec396 to
32f677f
Compare
Apply flex centering on datatable-scroller when it contains empty-content to ensure vertical and horizontal centering within the body.
32f677f to
ca0b038
Compare
Apply flex centering on datatable-scroller when it contains empty-content to ensure vertical and horizontal centering within the body.
What kind of change does this PR introduce? (check one with "x")
What is the current behavior? (You can also link to an open issue here)
The empty-content slot only uses computed sizes and does not do any vertical or horizontal alignment.
What is the new behavior?
The empty-content slot does vertical and horizontal alignment of the content.
Does this PR introduce a breaking change? (check one with "x")
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...
Other information: