Skip to content
Merged
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
71 changes: 71 additions & 0 deletions src/grid/tests/unit/widgets/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,75 @@ describe('Body', () => {
)
);
});

describe('pageChange', () => {
it('should call pageChange with first page at scroll 0', () => {
const pageChangeStub = stub();
const page: any[] = [];
for (let i = 0; i < 100; i++) {
const item = { id: 'id' };
page.push(item);
}

const h = harness(() =>
w(Body, {
totalRows: 1000,
pageSize: 100,
height: 400,
pages: {
'page-1': page
},
columnConfig: [] as any,
fetcher: noop,
updater: noop,
pageChange: pageChangeStub,
onScroll: noop
})
);

h.trigger('@root', 'onscroll', {
target: {
scrollTop: 0,
scrollLeft: 0
}
});
h.expect(() => h.getRender());
assert.isTrue(pageChangeStub.calledWith(1));
});

it('should use middle row if start and end pages are different', () => {
const pageChangeStub = stub();
const page: any[] = [];
for (let i = 0; i < 100; i++) {
const item = { id: 'id' };
page.push(item);
}

const h = harness(() =>
w(Body, {
totalRows: 1000,
pageSize: 100,
height: 400,
pages: {
'page-1': page
},
columnConfig: [] as any,
fetcher: noop,
updater: noop,
pageChange: pageChangeStub,
onScroll: noop
})
);
// scroll to row 286
h.trigger('@root', 'onscroll', {
target: {
scrollTop: 10000,
scrollLeft: 0
}
});
// force a render
h.expect(() => h.getRender());
assert.isTrue(pageChangeStub.calledWith(3));
});
});
});
10 changes: 5 additions & 5 deletions src/grid/tests/unit/widgets/Grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Grid', () => {
);

h.expect(() =>
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table' }, [
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table', 'aria-rowcount': null }, [
v('div', {
key: 'header',
scrollLeft: 0,
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Grid', () => {
);

h.expect(() =>
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table' }, [
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table', 'aria-rowcount': '100' }, [
v('div', {
key: 'header',
scrollLeft: 0,
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('Grid', () => {
);

h.expect(() =>
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table' }, [
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table', 'aria-rowcount': null }, [
v('div', {
key: 'header',
scrollLeft: 0,
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('Grid', () => {
);

h.expect(() =>
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table' }, [
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table', 'aria-rowcount': null }, [
v('div', {
key: 'header',
scrollLeft: 0,
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('Grid', () => {
h.trigger('@body', 'onScroll', 10);

h.expect(() =>
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table' }, [
v('div', { key: 'root', classes: [css.root, fixedCss.rootFixed], role: 'table', 'aria-rowcount': null }, [
v('div', {
key: 'header',
scrollLeft: 10,
Expand Down
20 changes: 10 additions & 10 deletions src/grid/tests/unit/widgets/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe('Header', () => {
);
h.expect(() =>
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [v('div', {}, ['First Name'])])
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': null }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': null }, [v('div', {}, ['First Name'])])
])
);
});
Expand All @@ -70,8 +70,8 @@ describe('Header', () => {

h.expect(() =>
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': null }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': null }, [
v('div', {
classes: [css.sortable, null, null, null],
onclick: noop
Expand Down Expand Up @@ -118,8 +118,8 @@ describe('Header', () => {

h.expect(() =>
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': null }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': 'ascending' }, [
v('div', {
classes: [css.sortable, css.sorted, null, css.asc],
onclick: noop
Expand Down Expand Up @@ -166,8 +166,8 @@ describe('Header', () => {

h.expect(() =>
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': null }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': 'descending' }, [
v('div', {
classes: [css.sortable, css.sorted, css.desc, null],
onclick: noop
Expand Down Expand Up @@ -214,8 +214,8 @@ describe('Header', () => {

h.expect(() =>
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader' }, [
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': null }, [v('div', {}, ['Title'])]),
v('div', { classes: [css.cell, fixedCss.cellFixed], role: 'columnheader', 'aria-sort': null }, [
v('div', {
classes: [css.sortable, null, null, null],
onclick: noop
Expand Down
6 changes: 3 additions & 3 deletions src/grid/tests/unit/widgets/Row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const noop = () => {};
describe('Row', () => {
it('should render without columns', () => {
const h = harness(() => w(Row, { id: 1, item: {}, columnConfig: [] as any, updater: noop }));
h.expect(() => v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row' }, []));
h.expect(() => v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row', 'aria-rowindex': '2' }, []));
});

it('should render items for column config', () => {
Expand All @@ -24,7 +24,7 @@ describe('Row', () => {
};
const h = harness(() => w(Row, { id: 1, item: { id: 'id' }, columnConfig: [columnConfig], updater: noop }));
h.expect(() =>
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row' }, [
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row', 'aria-rowindex': '2' }, [
w(Cell, { key: 'id', updater: noop, value: 'id', editable: undefined, rawValue: 'id' })
])
);
Expand All @@ -38,7 +38,7 @@ describe('Row', () => {
};
const h = harness(() => w(Row, { id: 1, item: { id: 'id' }, columnConfig: [columnConfig], updater: noop }));
h.expect(() =>
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row' }, [
v('div', { classes: [css.root, fixedCss.rootFixed], role: 'row', 'aria-rowindex': '2' }, [
w(Cell, { key: 'id', updater: noop, value: 'transformed', editable: undefined, rawValue: 'id' })
])
);
Expand Down
3 changes: 2 additions & 1 deletion src/grid/widgets/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export default class Body<S> extends ThemedMixin(WidgetBase)<BodyProperties<S>>
if (!endData.length) {
fetcher(endPage, pageSize);
}
pageChange(endPage);
const midScreenPage = Math.max(Math.ceil((start + this._rowsInView / 2) / pageSize), 1);
pageChange(midScreenPage);
data = [...data, ...endData];
} else {
pageChange(startPage);
Expand Down
7 changes: 6 additions & 1 deletion src/grid/widgets/Grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ export default class Grid<S> extends ThemedMixin(WidgetBase)<GridProperties<S>>
return v('div', { key: 'root', classes: [this.theme(css.root), fixedCss.rootFixed], role: 'table' });
}

return v('div', { key: 'root', classes: [this.theme(css.root), fixedCss.rootFixed], role: 'table' }, [
return v('div', {
key: 'root',
classes: [this.theme(css.root), fixedCss.rootFixed],
role: 'table',
'aria-rowcount': meta.total ? `${meta.total}` : null
}, [
v('div', {
key: 'header',
scrollLeft: this._scrollLeft,
Expand Down
14 changes: 10 additions & 4 deletions src/grid/widgets/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,27 @@ export default class Header extends ThemedMixin(WidgetBase)<HeaderProperties> {
title = column.title;
}
let headerProperties = {};
const isSorted = sort && sort.columnId === column.id;
const isSortedAsc = sort && sort.columnId === column.id && sort.direction === 'asc';
if (column.sortable) {
headerProperties = {
classes: [
this.theme(css.sortable),
sort && sort.columnId === column.id ? this.theme(css.sorted) : null,
sort && sort.columnId === column.id && sort.direction === 'desc' ? this.theme(css.desc) : null,
sort && sort.columnId === column.id && sort.direction === 'asc' ? this.theme(css.asc) : null
isSorted ? this.theme(css.sorted) : null,
isSorted && !isSortedAsc ? this.theme(css.desc) : null,
isSortedAsc ? this.theme(css.asc) : null
],
onclick: () => {
this._sortColumn(column.id);
}
};
}

return v('div', { classes: [this.theme(css.cell), fixedCss.cellFixed], role: 'columnheader' }, [
return v('div', {
'aria-sort': isSorted ? isSortedAsc ? 'ascending' : 'descending' : null,
classes: [this.theme(css.cell), fixedCss.cellFixed],
role: 'columnheader'
}, [
v('div', headerProperties, [
title,
column.sortable ? v('button', {
Expand Down
2 changes: 1 addition & 1 deletion src/grid/widgets/Row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export default class Row extends ThemedMixin(WidgetBase)<RowProperties> {
[] as DNode[]
);

return v('div', { classes: [this.theme(css.root), fixedCss.rootFixed], role: 'row' }, columns);
return v('div', { classes: [this.theme(css.root), fixedCss.rootFixed], role: 'row', 'aria-rowindex': `${id + 1}` }, columns);
}
}