Skip to content

Commit

Permalink
fix(component): update type definition to prevent primitive values as…
Browse files Browse the repository at this point in the history
… items (#2953)

* fix: update type definition to prevent primitive values as items

* fix: typecheck
  • Loading branch information
ryo-manba committed May 19, 2024
1 parent 7df2c71 commit c8f792c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .changeset/great-singers-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@nextui-org/autocomplete": patch
"@nextui-org/dropdown": patch
"@nextui-org/listbox": patch
"@nextui-org/menu": patch
"@nextui-org/select": patch
"@nextui-org/tabs": patch
"@nextui-org/use-aria-multiselect": patch
---

Fix update type definition to prevent primitive values as items (#2938)
4 changes: 2 additions & 2 deletions packages/components/autocomplete/src/autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ function Autocomplete<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLI
);
}

export type AutocompleteProps<T = object> = Props<T> & {ref?: Ref<HTMLElement>};
export type AutocompleteProps<T extends object = object> = Props<T> & {ref?: Ref<HTMLElement>};

// forwardRef doesn't support generic parameters, so cast the result to the correct type
export default forwardRef(Autocomplete) as <T = object>(
export default forwardRef(Autocomplete) as <T extends object>(
props: AutocompleteProps<T>,
) => ReactElement;

Expand Down
6 changes: 3 additions & 3 deletions packages/components/dropdown/src/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ForwardedRef, ReactElement, Ref} from "react";

import {useDropdownContext} from "./dropdown-context";

interface Props<T> extends Omit<MenuProps<T>, "menuProps"> {}
interface Props<T extends object = object> extends Omit<MenuProps<T>, "menuProps"> {}

function DropdownMenu<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLUListElement>) {
const {getMenuProps} = useDropdownContext();
Expand All @@ -20,10 +20,10 @@ function DropdownMenu<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLU
);
}

export type DropdownMenuProps<T = object> = Props<T> & {ref?: Ref<HTMLElement>};
export type DropdownMenuProps<T extends object = object> = Props<T> & {ref?: Ref<HTMLElement>};

// forwardRef doesn't support generic parameters, so cast the result to the correct type
export default forwardRef(DropdownMenu) as <T = object>(
export default forwardRef(DropdownMenu) as <T extends object>(
props: DropdownMenuProps<T>,
) => ReactElement;

Expand Down
2 changes: 1 addition & 1 deletion packages/components/dropdown/src/use-dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function useDropdown(props: UseDropdownProps) {
};
};

const getMenuProps = <T>(
const getMenuProps = <T extends object>(
props?: Partial<MenuProps<T>>,
_ref: Ref<any> | null | undefined = null,
) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/listbox/src/listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function Listbox<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLUListE

Listbox.displayName = "NextUI.Listbox";

export type ListboxProps<T = object> = Props<T> & {ref?: Ref<HTMLElement>};
export type ListboxProps<T extends object = object> = Props<T> & {ref?: Ref<HTMLElement>};

// forwardRef doesn't support generic parameters, so cast the result to the correct type
export default forwardRef(Listbox) as <T = object>(props: ListboxProps<T>) => ReactElement;
export default forwardRef(Listbox) as <T extends object>(props: ListboxProps<T>) => ReactElement;
4 changes: 2 additions & 2 deletions packages/components/menu/src/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function Menu<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLUListElem
);
}

export type MenuProps<T = object> = Props<T> & {ref?: Ref<HTMLElement>};
export type MenuProps<T extends object = object> = Props<T> & {ref?: Ref<HTMLElement>};

// forwardRef doesn't support generic parameters, so cast the result to the correct type
export default forwardRef(Menu) as <T = object>(props: MenuProps<T>) => ReactElement;
export default forwardRef(Menu) as <T extends object>(props: MenuProps<T>) => ReactElement;

Menu.displayName = "NextUI.Menu";
4 changes: 2 additions & 2 deletions packages/components/select/src/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ function Select<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLSelectE
);
}

export type SelectProps<T = object> = Props<T> & {ref?: Ref<HTMLElement>};
export type SelectProps<T extends object = object> = Props<T> & {ref?: Ref<HTMLElement>};

// forwardRef doesn't support generic parameters, so cast the result to the correct type
export default forwardRef(Select) as <T = object>(props: SelectProps<T>) => ReactElement;
export default forwardRef(Select) as <T extends object>(props: SelectProps<T>) => ReactElement;

Select.displayName = "NextUI.Select";
4 changes: 2 additions & 2 deletions packages/components/tabs/src/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function Tabs<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLDivElemen
return renderTabs;
}

export type TabsProps<T = object> = Props<T> & {ref?: Ref<HTMLElement>};
export type TabsProps<T extends object = object> = Props<T> & {ref?: Ref<HTMLElement>};

// forwardRef doesn't support generic parameters, so cast the result to the correct type
export default forwardRef(Tabs) as <T = object>(props: TabsProps<T>) => ReactElement;
export default forwardRef(Tabs) as <T extends object>(props: TabsProps<T>) => ReactElement;

Tabs.displayName = "NextUI.Tabs";

0 comments on commit c8f792c

Please sign in to comment.