-
-
Notifications
You must be signed in to change notification settings - Fork 362
fix(Table): include padding in auto-fit column width #6876
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
Conversation
Updated autoFitColumnWidth to calculate the header cell width using the <th> element directly instead of querying for a child span. This ensures more accurate column width fitting when including the header.
|
Thanks for your PR, @AApuci. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideautoFitColumnWidth now accounts for header cell padding by computing styles directly on the element, leading to more accurate column width measurements. Class diagram for updated autoFitColumnWidth logicclassDiagram
class Table {
options: Object
}
class Column {
}
class autoFitColumnWidth {
+async (table, col)
}
Table <|-- autoFitColumnWidth
Column <|-- autoFitColumnWidth
class "th (header cell)" {
+getComputedStyle()
+querySelector('.table-cell')
}
autoFitColumnWidth --> "th (header cell)" : uses
"th (header cell)" --> "span.table-cell" : queries
Flow diagram for header cell width calculation in autoFitColumnWidthflowchart TD
A["Start autoFitColumnWidth(table, col)"] --> B["Check fitColumnWidthIncludeHeader option"]
B -->|true| C["Find closest th element to col"]
C --> D["Query .table-cell span inside th"]
D --> E["Calculate cell width using calcCellWidth(span)"]
C --> F["Get computed style of th"]
F --> G["Extract padding-left and padding-right"]
E --> H["Add margin (padding) to maxWidth"]
G --> H
H --> I["Continue with autoFitColumnWidth logic"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Add a null check for
thbefore callingcalcCellWidthto avoid potential runtime errors on unexpected DOM structures. - Confirm that
calcCellWidthaccounts for padding, borders, and other CSS on the<th>itself to ensure the measurement is accurate. - Evaluate performance implications of measuring the entire
<th>element instead of the inner span, especially for tables with many header cells.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add a null check for `th` before calling `calcCellWidth` to avoid potential runtime errors on unexpected DOM structures.
- Confirm that `calcCellWidth` accounts for padding, borders, and other CSS on the `<th>` itself to ensure the measurement is accurate.
- Evaluate performance implications of measuring the entire `<th>` element instead of the inner span, especially for tables with many header cells.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6876 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 739 739
Lines 31765 31765
Branches 4466 4466
=========================================
Hits 31765 31765
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
|
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor.js:748-750` </location>
<code_context>
const span = th.querySelector('.table-cell');
- maxWidth = Math.max(maxWidth, calcCellWidth(span));
+ const thStyle = getComputedStyle(th);
+ const margin = parseFloat(thStyle.getPropertyValue('padding-left')) + parseFloat(thStyle.getPropertyValue('padding-right'))
+ maxWidth = Math.max(maxWidth, calcCellWidth(span)) + margin;
}
</code_context>
<issue_to_address>
**suggestion:** Handle NaN results from parseFloat for padding values.
Default to 0 if parseFloat returns NaN to ensure margin calculation is reliable.
```suggestion
const thStyle = getComputedStyle(th);
const paddingLeft = parseFloat(thStyle.getPropertyValue('padding-left'));
const paddingRight = parseFloat(thStyle.getPropertyValue('padding-right'));
const safePaddingLeft = isNaN(paddingLeft) ? 0 : paddingLeft;
const safePaddingRight = isNaN(paddingRight) ? 0 : paddingRight;
const margin = safePaddingLeft + safePaddingRight;
maxWidth = Math.max(maxWidth, calcCellWidth(span)) + margin;
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@sourcery-ai summary |
Updated autoFitColumnWidth to calculate the header cell width using the element directly instead of querying for a child span. This ensures more accurate column width fitting when including the header.
Link issues
fixes #6879
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Bug Fixes: