Skip to content

Commit

Permalink
fix(List): calling onLoadMore function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Kharitonov committed Jan 29, 2024
1 parent 7366c9b commit 147fff3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class List<T = unknown> extends React.Component<ListProps<T>, ListState<T
refFilter = React.createRef<HTMLInputElement>();
refContainer = React.createRef<any>();

Check warning on line 94 in src/components/List/List.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
blurTimer: ReturnType<typeof setTimeout> | null = null;
loadingItem = {value: '__LIST_ITEM_LOADING__', disabled: true} as unknown as ListItemData<
loadingItem = {value: '__LIST_ITEM_LOADING__', disabled: false} as unknown as ListItemData<
T & {value: string}
>;
uniqId = getUniqId();
Expand Down Expand Up @@ -518,11 +518,13 @@ export class List<T = unknown> extends React.Component<ListProps<T>, ListState<T
};

private handleKeyMove(event: React.KeyboardEvent, step: number, defaultItemIndex = 0) {
event.preventDefault();
const {activeItem = defaultItemIndex} = this.state;
this.activateItem(
List.findNextIndex<T>(this.state.items, activeItem + step, Math.sign(step)),
);

event.preventDefault();

const items = this.getItemsWithLoading();

this.activateItem(List.findNextIndex<T>(items, activeItem + step, Math.sign(step)));
}

private handleFocus = () => {
Expand Down
21 changes: 21 additions & 0 deletions src/components/List/__stories__/List.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,28 @@ export const RenderItem = RenderItemTemplate.bind({});
RenderItem.args = {
items,
renderItem: (item) => `🔥🔥🔥 ${item} 🔥🔥🔥`,
};

const TemplateWithState: ComponentStory<ComponentType> = (args) => {
const [items, setItems] = React.useState(args.items);

Check warning on line 50 in src/components/List/__stories__/List.stories.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'items' is already declared in the upper scope on line 20 column 7

const onLoadMore = () => {
// delay for fetching new real items
setTimeout(() => {
setItems([...items, ...args.items]);
}, 300);
};

return <List {...args} items={items} onLoadMore={onLoadMore} />;
};

export const WithLoadingMoreItems = TemplateWithState.bind({});
WithLoadingMoreItems.args = {
items: ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'],
itemsHeight: 150,
itemHeight: 28,
loading: true,
virtualized: false,
};

const ShowcaseTemplate: ComponentStory<ComponentType> = () => <ListShowcase />;
Expand Down

0 comments on commit 147fff3

Please sign in to comment.