Skip to content

Commit e535178

Browse files
committed
Accept whitespace separators in grid rows and cols properties
1 parent a169810 commit e535178

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

apps/tests/layouts/grid-layout-tests.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,19 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
512512
TKUnit.assertAreClose(btn.layoutLeft, 25, DELTA, "horizontal margins");
513513
}
514514

515-
public test_set_columns_in_XML() {
515+
public test_set_columns_in_XML_comma_separator() {
516516
var p = <page.Page>builder.parse("<Page><GridLayout columns=\"auto, *, 10*, 100 \"><Button/></GridLayout></Page>");
517517
var grid = <layout.GridLayout>p.content;
518+
this.assertColumns(grid);
519+
}
520+
521+
public test_set_columns_in_XML_space_separator() {
522+
var p = <page.Page>builder.parse("<Page><GridLayout columns=\"auto * 10* 100 \"><Button/></GridLayout></Page>");
523+
var grid = <layout.GridLayout>p.content;
524+
this.assertColumns(grid);
525+
}
518526

527+
private assertColumns(grid: layout.GridLayout) {
519528
var columns: Array<layout.ItemSpec> = grid.getColumns();
520529

521530
TKUnit.assertEqual(columns.length, 4, "columns.length");
@@ -531,10 +540,19 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
531540
TKUnit.assertEqual(columns[3].value, 100, "columns[3].value");
532541
}
533542

534-
public test_set_rows_in_XML() {
543+
public test_set_rows_in_XML_comma_separator() {
535544
var p = <page.Page>builder.parse("<Page><GridLayout rows=\"auto, *, 10*, 100 \"><Button/></GridLayout></Page>");
536545
var grid = <layout.GridLayout>p.content;
546+
this.assertRows(grid);
547+
}
548+
public test_set_rows_in_XML_space_separator() {
549+
var p = <page.Page>builder.parse("<Page><GridLayout rows=\"auto * 10* 100 \"><Button/></GridLayout></Page>");
550+
var grid = <layout.GridLayout>p.content;
551+
this.assertRows(grid);
552+
}
537553

554+
private assertRows(grid: layout.GridLayout) {
555+
var columns: Array<layout.ItemSpec> = grid.getColumns();
538556
var rows: Array<layout.ItemSpec> = grid.getRows();
539557

540558
TKUnit.assertEqual(rows.length, 4, "rows.length");

ui/layouts/grid-layout/grid-layout-common.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,18 @@ export class GridLayout extends layouts.LayoutBase implements definition.GridLay
313313

314314
private static parseItemSpecs(value: string): Array<ItemSpec> {
315315
var result = new Array<ItemSpec>();
316-
var arr = value.split(",");
316+
var arr = value.split(/[\s,]+/);
317317
for (var i = 0; i < arr.length; i++) {
318-
result.push(GridLayout.convertGridLength(arr[i].trim()));
318+
let str = arr[i].trim();
319+
if (str.length > 0) {
320+
result.push(GridLayout.convertGridLength(arr[i].trim()));
321+
}
319322
}
320323

321324
return result;
322325
}
323326

324327
private static convertGridLength(value: string): ItemSpec {
325-
326328
if (value === "auto") {
327329
return <ItemSpec>new definition.ItemSpec(1, definition.GridUnitType.auto);
328330
}

0 commit comments

Comments
 (0)