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

Add min-width on the columns #7557

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jcgueriaud1
Copy link
Contributor

@jcgueriaud1 jcgueriaud1 commented Jul 17, 2024

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

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/contributing/overview
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.
  • I have not completed some of the steps above and my pull request can be closed immediately.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

Only 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/JjQYBOQ
If you have 2 columns flex-grow:1 then the column group has flex-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 for min-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:

  • Instead of creating a width variable like max(min-width, calculatedWidth) I did the calculation in Javascript and set a result in pixel. But that it not working if the min-width is in rem or %

Maybe we should refactor Grid to use css grid instead of flexbox. But it's probably to difficult as an external contributor.

Copy link

sonarcloud bot commented Aug 8, 2024

@jcgueriaud1 jcgueriaud1 changed the title [DRAFT] Add min-width on the columns Add min-width on the columns Aug 8, 2024
@jcgueriaud1
Copy link
Contributor Author

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;
Copy link
Member

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untested code

Comment on lines +515 to +525
// 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}`;
}
});
Copy link
Member

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';
Copy link
Member

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', () => {
Copy link
Member

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);
});

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grid column minWidth and maxWidth
2 participants