From aa308d8eb2a2c381cfd1f635b20e265f2963baad Mon Sep 17 00:00:00 2001 From: Isaev Alexandr Date: Tue, 27 Aug 2024 19:01:13 +0300 Subject: [PATCH] fix(useList): support activeItemId in initialState prop (#1824) --- src/components/useList/hooks/useList.ts | 11 ++++++++--- src/components/useList/types.ts | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/useList/hooks/useList.ts b/src/components/useList/hooks/useList.ts index 11a99c9eb4..80a2ea08f7 100644 --- a/src/components/useList/hooks/useList.ts +++ b/src/components/useList/hooks/useList.ts @@ -1,7 +1,7 @@ /* eslint-disable valid-jsdoc */ import React from 'react'; -import type {ListState, UseListResult} from '../types'; +import type {InitialListParsedState, ListState, UseListResult} from '../types'; import {useFlattenListItems} from './useFlattenListItems'; import {useListParsedState} from './useListParsedState'; @@ -9,7 +9,10 @@ import type {UseListParsedStateProps} from './useListParsedState'; import {useListState} from './useListState'; import type {UseListStateProps} from './useListState'; -interface UseListProps extends UseListParsedStateProps, UseListStateProps { +interface UseListProps + extends UseListParsedStateProps, + Omit { + initialState?: Partial; controlledState?: Partial; } @@ -30,16 +33,18 @@ export const useList = ({ defaultExpandedState, }); - const initValues = React.useMemo(() => { + const initValues: InitialListParsedState = React.useMemo(() => { return { expandedById: {...initialState.expandedById, ...initialValues?.expandedById}, selectedById: {...initialState.selectedById, ...initialValues?.selectedById}, disabledById: {...initialState.disabledById, ...initialValues?.disabledById}, + activeItemId: initialValues?.activeItemId, }; }, [ initialState.disabledById, initialState.expandedById, initialState.selectedById, + initialValues?.activeItemId, initialValues?.disabledById, initialValues?.expandedById, initialValues?.selectedById, diff --git a/src/components/useList/types.ts b/src/components/useList/types.ts index 6af991e373..8aa8a22f6f 100644 --- a/src/components/useList/types.ts +++ b/src/components/useList/types.ts @@ -90,7 +90,7 @@ export type ListState = { export type InitialListParsedState = Pick< ListState, - 'disabledById' | 'expandedById' | 'selectedById' + 'disabledById' | 'expandedById' | 'selectedById' | 'activeItemId' >; export type ItemSchema = {