Skip to content

Commit

Permalink
Add name to useControllableReducer params
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Oct 12, 2023
1 parent f1ed0d3 commit 0a8a9d2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/mui-base/src/useDropdown/useDropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function useDropdown(parameters: UseDropdownParameters = {}) {
initialState: defaultOpen ? { open: true } : { open: false },
onStateChange: handleStateChange,
reducer: dropdownReducer,
name: 'useDropdown',
});

React.useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-base/src/useList/useList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function useList<
reducerActionContext = EMPTY_OBJECT as CustomActionContext,
selectionMode = 'single',
stateReducer: externalReducer,
name = 'useList',
} = params;

if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -222,6 +223,7 @@ function useList<
controlledProps,
stateComparers,
onStateChange: handleStateChange,
name,
});

const { highlightedValue, selectedValues } = state;
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-base/src/useList/useList.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ export interface UseListParameters<
ListActionContext<ItemValue> & CustomActionContext
>,
) => State;
/**
* The name of the hook or component
*/
name?: string;
}

export interface ListItemState {
Expand Down
8 changes: 8 additions & 0 deletions packages/mui-base/src/utils/useControllableReducer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('useControllableReducer', () => {
reducer,
controlledProps: {},
initialState: { make: 'Mazda', model: '3', productionYear: 2022 },
name: 'TestReducer',
};

function TestComponent() {
Expand All @@ -73,6 +74,7 @@ describe('useControllableReducer', () => {
reducer: (state) => state,
controlledProps: {},
initialState: { make: 'Mazda', model: '3', productionYear: 2022 },
name: 'TestReducer',
};

function TestComponent() {
Expand Down Expand Up @@ -109,6 +111,7 @@ describe('useControllableReducer', () => {
const reducerParameters: ControllableReducerParameters<TestState, SetMakeAction> = {
reducer,
initialState: { make: 'Mazda', model: '3', productionYear: 2022 },
name: 'TestReducer',
};

function TestComponent(props: { make: string }) {
Expand Down Expand Up @@ -136,6 +139,7 @@ describe('useControllableReducer', () => {
const reducerParameters: ControllableReducerParameters<TestState, SetMakeAction> = {
reducer: (state) => state,
initialState: { make: 'Mazda', model: '3', productionYear: 2022 },
name: 'TestReducer',
};

function TestComponent(props: { make: string }) {
Expand Down Expand Up @@ -166,6 +170,7 @@ describe('useControllableReducer', () => {
const reducerParameters: ControllableReducerParameters<TestState, SetMakeAction> = {
reducer: (state) => state,
initialState: { make: 'Mazda', model: '3', productionYear: 2022 },
name: 'TestReducer',
};

function TestComponent(props: { make?: string }) {
Expand Down Expand Up @@ -227,6 +232,7 @@ describe('useControllableReducer', () => {
a.every((v, i) => v === b[i]),
},
onStateChange: onStateChangeSpy,
name: 'TestReducer',
};

function TestComponent() {
Expand Down Expand Up @@ -267,6 +273,7 @@ describe('useControllableReducer', () => {
controlledProps: {},
initialState: { make: 'Mazda', model: '3', productionYear: 2022 },
onStateChange: handleChange,
name: 'TestReducer',
};

function TestComponent() {
Expand Down Expand Up @@ -318,6 +325,7 @@ describe('useControllableReducer', () => {
controlledProps: {},
initialState: { make: 'Mazda', model: '3', productionYear: 2022 },
actionContext: { overrideProductionYear: 2016 },
name: 'TestReducer',
};

function TestComponent() {
Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/utils/useControllableReducer.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ export interface ControllableReducerParameters<
*/
onStateChange?: StateChangeCallback<State>;
/**
* Additional properties that will be added to the action.
* The name of the hook or component
*/
actionContext?: ActionContext;
/**
* Additional properties that will be added to the action.
*/
name: string;
}

/*
Expand Down

0 comments on commit 0a8a9d2

Please sign in to comment.