-
Notifications
You must be signed in to change notification settings - Fork 83
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
Add min-width on the columns #7557
Conversation
Quality Gate passedIssues Measures |
I guess the visual tests can't run from a fork |
* cells have different font sizes. Instead, use `rem` if you need | ||
* a length unit relative to the font size. | ||
*/ | ||
minWidth: string | null | undefined; |
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.
nit: space missing after this line
/** @private */ | ||
_minWidthChanged(minWidth) { | ||
if (this.parentElement && this.parentElement._columnPropChanged) { | ||
this.parentElement._columnPropChanged('minWidth'); |
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.
untested code
// update the columns without autowidth and set the min width | ||
const noAutoWidthCols = this._getColumns().filter((col) => !col.hidden && !col.autoWidth); | ||
|
||
noAutoWidthCols.forEach((col) => { | ||
const calculatedWidth = col.width; | ||
if (col.minWidth) { | ||
col.width = `max(${col.minWidth}, ${calculatedWidth})`; | ||
} else { | ||
col.width = `${calculatedWidth}`; | ||
} | ||
}); |
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.
untested code
@@ -0,0 +1,3 @@ | |||
import '../theme/lumo/lit-all-imports.js'; | |||
import '../src/lit-all-imports.js'; |
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.
Could align with the polymer test and import the styled grid (import '../lit-all-imports.js';
)
}); | ||
} | ||
|
||
describe('column auto-width', () => { |
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.
Is there a reason to have all min-width -specific tests in this separate test file instead of including, for example, the auto-width test to column-auto-width.common.js
(under "min-width" suite where necessary)?
As an example, adding the following (adjusted) test from this PR to column-resizing.common.js
right under "should resize the last non-hidden child column" would save us from replicating the same test setup here:
it('should resize the child columns with min-width', () => {
const columns = grid.querySelectorAll('vaadin-grid-column');
columns[0].minWidth = '120px';
columns[1].minWidth = '70px';
const headerRows = getRows(grid.$.header);
const groupCell = getRowCells(headerRows[0])[0];
const handle = groupCell.querySelector('[part~="resize-handle"]');
const cell = getRowCells(headerRows[1])[1];
const rect = cell.getBoundingClientRect();
const options = { node: handle };
expect(cell.clientWidth).to.equal(100);
fire('track', { state: 'start' }, options);
fire('track', { state: 'track', x: rect.right + (direction === 'rtl' ? -50 : 50), y: 0 }, options);
expect(cell.clientWidth).to.equal(direction === 'rtl' ? 70 : 150);
expect(groupCell.clientWidth).to.equal(direction === 'rtl' ? 190 : 270);
});
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.
For the resizing, I think there is no particular reason. For the other tests, they are using expectColumnWidthsToBeOk
with a regexp.
auto-width
is not what I'm testing that's the reason it's not in the auto-width
test file.
For example, I need to add at least a test case without auto-width
(that could be in an other file or in min-width
).
Let me add all the needed tests then we can check if they need to be in the existing test files or in one specific file.
Dear @jcgueriaud1 , there are some unresolved review comments. Are you planning to address those? |
No, I'm not planning to update this PR. In the current state of the PR, the changes between Maybe the way it's done is wrong and should be re-think differently. |
Description
Please list all relevant dependencies in this section and provide summary of the change, motivation and context.
Fixes vaadin/platform#6553
Type of change
Checklist
Additional for
Feature
type of changeOnly the
min-width
is implemented because the max-width with flex-grow are not working together if the columns are grouped. There is an example in html of the issue here: https://codepen.io/jcgueriaud/pen/JjQYBOQIf you have 2 columns
flex-grow:1
then the column group hasflex-grow:2
(1+1).But the max-width will "block" the column to grow at a certain point and the width of the group will be different.
Since the column doesn't have a
flex-shrink
property it's not an issue formin-width
.To avoid flaky test, I'm parsing the width of the columns like
max(min-width, calculatedWidth)
as a Regex and check the width with a delta.As an alternative of the implementation I tried:
max(min-width, calculatedWidth)
I did the calculation in Javascript and set a result in pixel. But that it not working if themin-width
is inrem
or%
Maybe we should refactor Grid to use css grid instead of flexbox. But it's probably to difficult as an external contributor.