Skip to content

Commit

Permalink
fix defaultSelectedItems and initialSelectedItems
Browse files Browse the repository at this point in the history
  • Loading branch information
moathabuhamad-cengage committed Nov 25, 2024
1 parent c47202e commit 1e6333a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
12 changes: 5 additions & 7 deletions packages/react-magma-dom/src/components/Select/MultiSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as React from 'react';
import {
instanceOfDefaultItemObject,
MultiSelectProps,
} from '.';
import { instanceOfDefaultItemObject, MultiSelectProps } from '.';
import { useMultipleSelection, useSelect } from 'downshift';
import { CloseIcon } from 'react-magma-icons';
import { ItemsList } from './ItemsList';
Expand Down Expand Up @@ -54,10 +51,11 @@ export function MultiSelect<T>(props: MultiSelectProps<T>) {
} = props;

function checkSelectedItemValidity(itemToCheck: T) {
return (
!isItemDisabled(itemToCheck) &&
items.findIndex(i => itemToString(i) === itemToString(itemToCheck)) !== -1
const itemIndex = items.findIndex(
i => itemToString(i) === itemToString(itemToCheck)
);

return !isItemDisabled(itemToCheck) && itemIndex !== -1;
}

function getFilteredItemIndex(item: T, filteredItems: T[]) {
Expand Down
12 changes: 6 additions & 6 deletions packages/react-magma-dom/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export function Select<T>(props: SelectProps<T>) {
}

function getValidItem(itemToCheck: T, key: string): object {
if (isItemDisabled(itemToCheck)) {
const itemIndex = items.findIndex(
i => itemToString(i) === itemToString(itemToCheck)
);

if (itemIndex === -1 || isItemDisabled(itemToCheck)) {
return { [key]: null };
}

return items.findIndex(
i => itemToString(i) === itemToString(itemToCheck)
) !== -1
? { [key]: itemToCheck }
: { [key]: null };
return { [key]: itemToCheck };
}

function getValidItemIndex(indexToCheck: number) {
Expand Down
9 changes: 0 additions & 9 deletions packages/react-magma-dom/src/components/Select/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export const StyledItem = styled('li')<{
line-height: 24px;
margin: 0;
padding: 8px 16px;
cursor: ${props => (props.isDisabled ? 'not-allowed' : 'default')};
&:hover {
background: ${props => buildListHoverColor(props)};
border-color: transparent;
Expand Down Expand Up @@ -183,14 +182,6 @@ export const SelectedItemButton = styled.button<{
position: relative;
white-space: nowrap;
min-width: 0%;
outline-offset: 2px;
&:focus {
outline: 2px solid
${props =>
props.isInverse
? props.theme.colors.focusInverse
: props.theme.colors.focus};
}
`;

export const IconWrapper = styled.span`
Expand Down

0 comments on commit 1e6333a

Please sign in to comment.