Skip to content

Commit

Permalink
fix: table does not automatically scroll to the top when change page …
Browse files Browse the repository at this point in the history
…size (#19465)

* 🐛 (Table): fix scrollToFirstRow

fix table does not automatically scroll to the top when change page size
close #19464

* ✅ (Table): add test case for scrollToFirstRow

* 👌 (Table): change Trigger to .ant-select

Co-Authored-By: 骗你是小猫咪 <darryshaw@gmail.com>
  • Loading branch information
MrHeer and shaodahong committed Nov 2, 2019
1 parent 92caa2d commit 3d8b9df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions components/table/Table.tsx
Expand Up @@ -807,7 +807,7 @@ class Table<T> extends React.Component<InternalTableProps<T>, TableState<T>> {
current: this.state.pagination.current,
};
}
this.setState(newState, () => this.scrollToFirstRow());
this.setState(newState, this.scrollToFirstRow);

this.props.store.setState({
selectionDirty: false,
Expand All @@ -834,7 +834,7 @@ class Table<T> extends React.Component<InternalTableProps<T>, TableState<T>> {
pageSize,
current,
};
this.setState({ pagination: nextPagination });
this.setState({ pagination: nextPagination }, this.scrollToFirstRow);

const { onChange } = this.props;
if (onChange) {
Expand Down Expand Up @@ -878,7 +878,7 @@ class Table<T> extends React.Component<InternalTableProps<T>, TableState<T>> {

// Controlled
if (this.getSortOrderColumns().length === 0) {
this.setState(newState, () => this.scrollToFirstRow());
this.setState(newState, this.scrollToFirstRow);
}

const { onChange } = this.props;
Expand Down
22 changes: 20 additions & 2 deletions components/table/__tests__/Table.pagination.test.js
Expand Up @@ -79,14 +79,32 @@ describe('Table.pagination', () => {
expect(wrapper.find('.ant-pagination.mini')).toHaveLength(1);
});

// TODO
it('should scroll to first row when page change', () => {
const wrapper = mount(createTable({ scroll: { y: 20 } }));
const wrapper = mount(
createTable({ scroll: { y: 20 }, pagination: { showSizeChanger: true, pageSize: 2 } }),
);
const scrollToSpy = jest.spyOn(
wrapper
.find('Table')
.first()
.instance(),
'scrollToFirstRow',
);
expect(scrollToSpy).toHaveBeenCalledTimes(0);

wrapper
.find('Pager')
.last()
.simulate('click');
expect(scrollToSpy).toHaveBeenCalledTimes(1);

wrapper.find('.ant-select').simulate('click');
wrapper
.find('MenuItem')
.find('li')
.last()
.simulate('click');
expect(scrollToSpy).toHaveBeenCalledTimes(2);
});

it('fires change event', () => {
Expand Down

0 comments on commit 3d8b9df

Please sign in to comment.