Skip to content

Commit

Permalink
Fix pluralization of listbox' selectedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Mar 2, 2023
1 parent 091c288 commit 8cb3eab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import defaultReducer from './defaultListboxReducer';

describe('useListbox defaultReducer', () => {
describe('action: setControlledValue', () => {
it("assigns the provided value to the state's selectedValue", () => {
it("assigns the provided value to the state's selectedValues", () => {
const state: ListboxState<string> = {
highlightedValue: 'a',
selectedValues: [],
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('useListbox defaultReducer', () => {
});

describe('action: optionClick', () => {
it('sets the selectedValue to the clicked value', () => {
it('sets the selectedValues to the clicked value', () => {
const state: ListboxState<string> = {
highlightedValue: 'a',
selectedValues: [],
Expand All @@ -82,7 +82,7 @@ describe('useListbox defaultReducer', () => {
expect(result.selectedValues).to.deep.equal(['two']);
});

it('replaces the selectedValue with the clicked value if selectionLimit = 1', () => {
it('replaces the selectedValues with the clicked value if selectionLimit = 1', () => {
const state: ListboxState<string> = {
highlightedValue: 'a',
selectedValues: ['one'],
Expand Down Expand Up @@ -324,7 +324,7 @@ describe('useListbox defaultReducer', () => {
expect(result.selectedValues).to.deep.equal(['two']);
});

it('replaces the selectedValue with the highlighted value if selectionLimit = 1', () => {
it('replaces the selectedValues with the highlighted value if selectionLimit = 1', () => {
const state: ListboxState<string> = {
highlightedValue: 'two',
selectedValues: ['one'],
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/useListbox/useControllableReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getControlledState<TOption>(
props: UseListboxParametersWithDefaults<TOption>,
) {
if (props.value !== undefined) {
return { ...internalState, selectedValue: props.value };
return { ...internalState, selectedValues: props.value };
}

return internalState;
Expand Down
5 changes: 3 additions & 2 deletions packages/mui-base/src/useTabsList/useTabsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function useTabsList(parameters: UseTabsListParameters): UseTabsListReturnValue
listOrientation = isRtl ? 'horizontal-rtl' : 'horizontal-ltr';
}

const stateReducer: ListboxReducer<string | number> = React.useCallback(
const stateReducer: ListboxReducer<string | number | null> = React.useCallback(
(state, action) => {
const newState = defaultListboxReducer(state, action);

Expand All @@ -81,7 +81,7 @@ function useTabsList(parameters: UseTabsListParameters): UseTabsListReturnValue
if (selectionFollowsFocus) {
return {
...newState,
selectedValue: [newState.highlightedValue],
selectedValues: [newState.highlightedValue],
};
}

Expand Down Expand Up @@ -126,6 +126,7 @@ function useTabsList(parameters: UseTabsListParameters): UseTabsListReturnValue
onChange: handleChange,
options: subitemKeys,
orientation: listOrientation,
selectionLimit: 1,
stateReducer,
value: listboxValue,
});
Expand Down

0 comments on commit 8cb3eab

Please sign in to comment.