Skip to content

Commit

Permalink
Merge pull request #821 from equinor/fix/onadd
Browse files Browse the repository at this point in the history
🩹 Fix bad type for onAddItem
  • Loading branch information
mariush2 authored Oct 21, 2024
2 parents 76036eb + bb26c35 commit 0c2e7dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/molecules/Select/ComboBox/ComboBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ export const ComboBoxInDialog: StoryFn = (args) => {
export const ComboBoxWithAdd: StoryFn = (args) => {
const [values, setValues] = useState<SelectOption<Item>[]>([]);
const handleOnSelect = (newValues: SelectOptionRequired[]) => {
actions('onSelect').onSelect(newValues);
setValues(newValues);
};

const handleOnAdd = (value: string): void => {
const handleOnAdd = (value: string) => {
actions('onItemAdd').onItemAdd(value);
const newItem = {
label: value,
Expand All @@ -241,7 +242,6 @@ export const ComboBoxWithAdd: StoryFn = (args) => {
{...args}
values={values as SelectOptionRequired[]}
items={FAKE_ITEMS}
groups={undefined}
onSelect={handleOnSelect}
onAddItem={handleOnAdd}
/>
Expand Down
4 changes: 3 additions & 1 deletion src/molecules/Select/ListSelectMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
NoTagFoundText,
} from 'src/molecules/Select/Select.styles';
import {
ListSelectMenuProps,
ListSelectProps,
MultiSelectCommon,
SelectMenuProps,
Expand All @@ -23,9 +24,10 @@ import { SelectMenuItem } from 'src/molecules/Select/SelectMenuItem';

export const ListSelectMenu = <T extends SelectOptionRequired>(
props: ListSelectProps<T> &
ListSelectMenuProps &
SelectMenuProps<T> &
(
| Omit<MultiSelectCommon<T>, 'onAddItem' | 'syncParentChildSelection'>
| Omit<MultiSelectCommon<T>, 'syncParentChildSelection'>
| SingleSelectCommon<T>
)
) => {
Expand Down
5 changes: 4 additions & 1 deletion src/molecules/Select/Select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ export interface GroupedSelectProps<T extends SelectOptionRequired> {

export interface ListSelectProps<T extends SelectOptionRequired> {
items: SelectOption<T>[];
onAddItem?: () => void;
groups?: undefined;
}

export interface ListSelectMenuProps {
onAddItem?: () => void;
}

export interface SelectMenuProps<T extends SelectOptionRequired> {
search: string;
itemRefs: MutableRefObject<(HTMLButtonElement | null)[]>;
Expand Down

0 comments on commit 0c2e7dd

Please sign in to comment.