Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,16 @@
* @see #setFlexGrow(int)
*
* @param width
* the width to set this column to, as a CSS-string, not
* {@code null}
* the width to set this column to, as a CSS-string, or
* {@code null} to reset the width to the default
* @return this column, for method chaining
*/
public Column<T> setWidth(String width) {
getElement().setProperty("width", width);
if (width != null) {
getElement().setProperty("width", width);

Check failure on line 634 in vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "width" 3 times.

See more on https://sonarcloud.io/project/issues?id=vaadin_flow-components&issues=AZ9fgidp-wgxbL1I6M4S&open=AZ9fgidp-wgxbL1I6M4S&pullRequest=9738
} else {
getElement().removeProperty("width");
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ void removeColumnTwice_throws() {
"The column with key 'first' is not owned by this Grid"));
}

@Test
void setWidth_getWidth() {
firstColumn.setWidth("100px");
Assertions.assertEquals("100px", firstColumn.getWidth());
Assertions.assertTrue(firstColumn.getElement().hasProperty("width"));
}

@Test
void setWidthNull_widthPropertyRemoved() {
firstColumn.setWidth("100px");
firstColumn.setWidth(null);
Assertions.assertNull(firstColumn.getWidth());
Assertions.assertFalse(firstColumn.getElement().hasProperty("width"));
}

@Test
void addColumn_defaultComparator() {
Grid<Person> grid = new Grid<>();
Expand Down
Loading