Skip to content

Commit

Permalink
fix(useList): support activeItemId in initialState prop (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaevAlexandr authored Aug 27, 2024
1 parent b953f18 commit aa308d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/components/useList/hooks/useList.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* 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';
import type {UseListParsedStateProps} from './useListParsedState';
import {useListState} from './useListState';
import type {UseListStateProps} from './useListState';

interface UseListProps<T> extends UseListParsedStateProps<T>, UseListStateProps {
interface UseListProps<T>
extends UseListParsedStateProps<T>,
Omit<UseListStateProps, 'initialState'> {
initialState?: Partial<InitialListParsedState>;
controlledState?: Partial<ListState>;
}

Expand All @@ -30,16 +33,18 @@ export const useList = <T>({
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,
Expand Down
2 changes: 1 addition & 1 deletion src/components/useList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type ListState = {

export type InitialListParsedState = Pick<
ListState,
'disabledById' | 'expandedById' | 'selectedById'
'disabledById' | 'expandedById' | 'selectedById' | 'activeItemId'
>;

export type ItemSchema = {
Expand Down

0 comments on commit aa308d8

Please sign in to comment.