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

[OverflowList] Always re-render items #3278

Merged
merged 4 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 9 additions & 3 deletions packages/core/src/components/overflow-list/overflowList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Boundary } from "../../common/boundary";
import * as Classes from "../../common/classes";
import { OVERFLOW_LIST_OBSERVE_PARENTS_CHANGED } from "../../common/errors";
import { DISPLAYNAME_PREFIX, IProps } from "../../common/props";
import { safeInvoke } from "../../common/utils";
import { safeInvoke, shallowCompareKeys } from "../../common/utils";
import { IResizeEntry, ResizeSensor } from "../resize-sensor/resizeSensor";

/** @internal - do not expose this type */
Expand Down Expand Up @@ -100,7 +100,7 @@ export interface IOverflowListState<T> {
visible: T[];
}

export class OverflowList<T> extends React.PureComponent<IOverflowListProps<T>, IOverflowListState<T>> {
export class OverflowList<T> extends React.Component<IOverflowListProps<T>, IOverflowListState<T>> {
public static displayName = `${DISPLAYNAME_PREFIX}.OverflowList`;

public static defaultProps: Partial<IOverflowListProps<any>> = {
Expand Down Expand Up @@ -156,8 +156,14 @@ export class OverflowList<T> extends React.PureComponent<IOverflowListProps<T>,
}
}

public shouldComponentUpdate(_nextProps: IOverflowListProps<T>, nextState: IOverflowListState<T>) {
return !(this.state !== nextState && shallowCompareKeys(this.state, nextState));
invliD marked this conversation as resolved.
Show resolved Hide resolved
}

public componentDidUpdate(_prevProps: IOverflowListProps<T>, prevState: IOverflowListState<T>) {
this.repartition(false);
if (!shallowCompareKeys(prevState, this.state)) {
this.repartition(false);
}
const { direction, overflow, lastOverflowCount } = this.state;
if (
// if a resize operation has just completed (transition to NONE)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/overflow-list/overflowListTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ describe("<OverflowList>", function(this) {
.waitForResize()).assertVisibleItems(...IDS);
});

it("shows fewer after shrinking", () => {
overflowList(45)
it("shows fewer after shrinking", async () => {
(await overflowList(45)
.assertVisibleItemSplit(4)
.setWidth(15)
.assertVisibleItemSplit(1);
.waitForResize()).assertVisibleItemSplit(1);
});

it("shows at least minVisibleItems", () => {
Expand Down