From 147fff3c19fd86c04167b59f0fd394b9df5a5883 Mon Sep 17 00:00:00 2001 From: Kirill Kharitonov Date: Mon, 29 Jan 2024 19:34:09 +0300 Subject: [PATCH 1/2] fix(List): calling onLoadMore function --- src/components/List/List.tsx | 12 ++++++----- .../List/__stories__/List.stories.tsx | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/components/List/List.tsx b/src/components/List/List.tsx index 3e8c3bee10..4fb2d291db 100644 --- a/src/components/List/List.tsx +++ b/src/components/List/List.tsx @@ -93,7 +93,7 @@ export class List extends React.Component, ListState(); refContainer = React.createRef(); blurTimer: ReturnType | 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(); @@ -518,11 +518,13 @@ export class List extends React.Component, ListState(this.state.items, activeItem + step, Math.sign(step)), - ); + + event.preventDefault(); + + const items = this.getItemsWithLoading(); + + this.activateItem(List.findNextIndex(items, activeItem + step, Math.sign(step))); } private handleFocus = () => { diff --git a/src/components/List/__stories__/List.stories.tsx b/src/components/List/__stories__/List.stories.tsx index c103bbbd9d..a3f8d74829 100644 --- a/src/components/List/__stories__/List.stories.tsx +++ b/src/components/List/__stories__/List.stories.tsx @@ -44,7 +44,28 @@ export const RenderItem = RenderItemTemplate.bind({}); RenderItem.args = { items, renderItem: (item) => `🔥🔥🔥 ${item} 🔥🔥🔥`, +}; + +const TemplateWithState: ComponentStory = (args) => { + const [items, setItems] = React.useState(args.items); + + const onLoadMore = () => { + // delay for fetching new real items + setTimeout(() => { + setItems([...items, ...args.items]); + }, 300); + }; + + return ; +}; + +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 = () => ; From aca7595667b2f31c5e0fb8fde8022e8333f13cf2 Mon Sep 17 00:00:00 2001 From: Kirill Kharitonov Date: Tue, 30 Jan 2024 16:12:03 +0300 Subject: [PATCH 2/2] fix: updated List story --- .../List/__stories__/List.stories.tsx | 14 ++-------- .../List/__stories__/ListWithLoader.scss | 6 +++++ .../List/__stories__/ListWithLoader.tsx | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 src/components/List/__stories__/ListWithLoader.scss create mode 100644 src/components/List/__stories__/ListWithLoader.tsx diff --git a/src/components/List/__stories__/List.stories.tsx b/src/components/List/__stories__/List.stories.tsx index a3f8d74829..7bb1c5562c 100644 --- a/src/components/List/__stories__/List.stories.tsx +++ b/src/components/List/__stories__/List.stories.tsx @@ -6,6 +6,7 @@ import {List, listDefaultProps} from '..'; import type {ListProps} from '..'; import {ListShowcase} from './ListShowcase'; +import {ListWithLoader} from './ListWithLoader'; type ComponentType = React.JSXElementConstructor>; @@ -46,18 +47,7 @@ RenderItem.args = { renderItem: (item) => `🔥🔥🔥 ${item} 🔥🔥🔥`, }; -const TemplateWithState: ComponentStory = (args) => { - const [items, setItems] = React.useState(args.items); - - const onLoadMore = () => { - // delay for fetching new real items - setTimeout(() => { - setItems([...items, ...args.items]); - }, 300); - }; - - return ; -}; +const TemplateWithState: ComponentStory = (args) => ; export const WithLoadingMoreItems = TemplateWithState.bind({}); WithLoadingMoreItems.args = { diff --git a/src/components/List/__stories__/ListWithLoader.scss b/src/components/List/__stories__/ListWithLoader.scss new file mode 100644 index 0000000000..4fe39f4e6d --- /dev/null +++ b/src/components/List/__stories__/ListWithLoader.scss @@ -0,0 +1,6 @@ +@use '../../variables'; +@use '../../../../styles/mixins'; + +.list-with-loader { + overflow: auto; +} diff --git a/src/components/List/__stories__/ListWithLoader.tsx b/src/components/List/__stories__/ListWithLoader.tsx new file mode 100644 index 0000000000..eb3f7c8b0d --- /dev/null +++ b/src/components/List/__stories__/ListWithLoader.tsx @@ -0,0 +1,26 @@ +import React from 'react'; + +import {cn} from '../../utils/cn'; +import {List} from '../List'; +import type {ListProps} from '../types'; + +import './ListWithLoader.scss'; + +const b = cn('list-with-loader'); + +export const ListWithLoader = (args: ListProps) => { + const [items, setItems] = React.useState(args.items); + + const onLoadMore = () => { + // delay for fetching new real items + setTimeout(() => { + setItems([...items, ...args.items]); + }, 300); + }; + + return ( +
+ +
+ ); +};