diff --git a/.changeset/breezy-bobcats-destroy.md b/.changeset/breezy-bobcats-destroy.md new file mode 100644 index 0000000000..e4465ee09f --- /dev/null +++ b/.changeset/breezy-bobcats-destroy.md @@ -0,0 +1,7 @@ +--- +"@nextui-org/pagination": patch +"@nextui-org/listbox": patch +"@nextui-org/menu": patch +--- + +Reverts the PR-4168 (#4256, #4246, #4244) diff --git a/packages/components/listbox/__tests__/listbox.test.tsx b/packages/components/listbox/__tests__/listbox.test.tsx index e77196aed1..60614536bf 100644 --- a/packages/components/listbox/__tests__/listbox.test.tsx +++ b/packages/components/listbox/__tests__/listbox.test.tsx @@ -124,40 +124,6 @@ describe("Listbox", () => { expect(() => wrapper.unmount()).not.toThrow(); }); - it("should not have anchor tag when href prop is not passed", () => { - render( - - New file - Copy link - Edit file - , - ); - - let anchorTag = document.getElementsByTagName("a")[0]; - - expect(anchorTag).toBeFalsy(); - }); - - it("should have anchor tag when href prop is passed", () => { - const href = "http://www.nextui.org/"; - - render( - - - New file - - Copy link - Edit file - , - ); - - let anchorTag = document.getElementsByTagName("a")[0]; - - expect(anchorTag).toBeTruthy(); - - expect(anchorTag).toHaveProperty("href", href); - }); - it("should work with single selection (controlled)", async () => { let onSelectionChange = jest.fn(); diff --git a/packages/components/listbox/src/listbox-item.tsx b/packages/components/listbox/src/listbox-item.tsx index 8a3f248de1..476f6c59d3 100644 --- a/packages/components/listbox/src/listbox-item.tsx +++ b/packages/components/listbox/src/listbox-item.tsx @@ -12,7 +12,6 @@ export interface ListboxItemProps const ListboxItem = (props: ListboxItemProps) => { const { Component, - FragmentWrapper, rendered, description, isSelectable, @@ -23,7 +22,6 @@ const ListboxItem = (props: ListboxItemProps) => { endContent, hideSelectedIcon, disableAnimation, - fragmentWrapperProps, getItemProps, getLabelProps, getWrapperProps, @@ -47,21 +45,19 @@ const ListboxItem = (props: ListboxItemProps) => { return ( - - {startContent} - {description ? ( -
- {rendered} - {description} -
- ) : ( + {startContent} + {description ? ( +
{rendered} - )} - {isSelectable && !hideSelectedIcon && ( - {selectedContent} - )} - {endContent} - + {description} +
+ ) : ( + {rendered} + )} + {isSelectable && !hideSelectedIcon && ( + {selectedContent} + )} + {endContent}
); }; diff --git a/packages/components/listbox/src/use-listbox-item.ts b/packages/components/listbox/src/use-listbox-item.ts index 820b32637f..5364c773dc 100644 --- a/packages/components/listbox/src/use-listbox-item.ts +++ b/packages/components/listbox/src/use-listbox-item.ts @@ -1,7 +1,7 @@ import type {ListboxItemBaseProps} from "./base/listbox-item-base"; import type {MenuItemVariantProps} from "@nextui-org/theme"; -import {useMemo, useRef, useCallback, Fragment} from "react"; +import {useMemo, useRef, useCallback} from "react"; import {listboxItem} from "@nextui-org/theme"; import { HTMLNextUIProps, @@ -50,7 +50,6 @@ export function useListboxItem(originalProps: UseListboxItemPr shouldHighlightOnFocus, hideSelectedIcon = false, isReadOnly = false, - href, ...otherProps } = props; @@ -59,12 +58,9 @@ export function useListboxItem(originalProps: UseListboxItemPr const domRef = useRef(null); - const Component = as || "li"; + const Component = as || (originalProps.href ? "a" : "li"); const shouldFilterDOMProps = typeof Component === "string"; - const FragmentWrapper = href ? "a" : Fragment; - const fragmentWrapperProps = href ? {href} : {}; - const {rendered, key} = item; const isDisabled = state.disabledKeys.has(key) || originalProps.isDisabled; @@ -173,7 +169,6 @@ export function useListboxItem(originalProps: UseListboxItemPr return { Component, - FragmentWrapper, domRef, slots, classNames, @@ -187,7 +182,6 @@ export function useListboxItem(originalProps: UseListboxItemPr selectedIcon, hideSelectedIcon, disableAnimation, - fragmentWrapperProps, getItemProps, getLabelProps, getWrapperProps, diff --git a/packages/components/menu/__tests__/menu.test.tsx b/packages/components/menu/__tests__/menu.test.tsx index 0b4ea75e87..eeaa3eb068 100644 --- a/packages/components/menu/__tests__/menu.test.tsx +++ b/packages/components/menu/__tests__/menu.test.tsx @@ -125,46 +125,6 @@ describe("Menu", () => { expect(() => wrapper.unmount()).not.toThrow(); }); - it("should not have anchor tag when href prop is not passed", () => { - render( - - New file - Copy link - Edit file - - Delete file - - , - ); - - let anchorTag = document.getElementsByTagName("a")[0]; - - expect(anchorTag).toBeFalsy(); - }); - - it("should have anchor tag when href prop is passed", () => { - const href = "http://www.nextui.org/"; - - render( - - - New file - - Copy link - Edit file - - Delete file - - , - ); - - let anchorTag = document.getElementsByTagName("a")[0]; - - expect(anchorTag).toBeTruthy(); - - expect(anchorTag).toHaveProperty("href", href); - }); - it("should work with single selection (controlled)", async () => { let onSelectionChange = jest.fn(); diff --git a/packages/components/menu/src/menu-item.tsx b/packages/components/menu/src/menu-item.tsx index 5e22e495a3..594bcd3963 100644 --- a/packages/components/menu/src/menu-item.tsx +++ b/packages/components/menu/src/menu-item.tsx @@ -12,7 +12,6 @@ export interface MenuItemProps const MenuItem = (props: MenuItemProps) => { const { Component, - FragmentWrapper, slots, classNames, rendered, @@ -26,7 +25,6 @@ const MenuItem = (props: MenuItemProps) => { endContent, disableAnimation, hideSelectedIcon, - fragmentWrapperProps, getItemProps, getLabelProps, getDescriptionProps, @@ -50,22 +48,20 @@ const MenuItem = (props: MenuItemProps) => { return ( - - {startContent} - {description ? ( -
- {rendered} - {description} -
- ) : ( + {startContent} + {description ? ( +
{rendered} - )} - {shortcut && {shortcut}} - {isSelectable && !hideSelectedIcon && ( - {selectedContent} - )} - {endContent} - + {description} +
+ ) : ( + {rendered} + )} + {shortcut && {shortcut}} + {isSelectable && !hideSelectedIcon && ( + {selectedContent} + )} + {endContent}
); }; diff --git a/packages/components/menu/src/use-menu-item.ts b/packages/components/menu/src/use-menu-item.ts index a150e8def2..b493e50bd5 100644 --- a/packages/components/menu/src/use-menu-item.ts +++ b/packages/components/menu/src/use-menu-item.ts @@ -2,7 +2,7 @@ import type {MenuItemBaseProps} from "./base/menu-item-base"; import type {MenuItemVariantProps} from "@nextui-org/theme"; import type {Node} from "@react-types/shared"; -import {useMemo, useRef, useCallback, Fragment} from "react"; +import {useMemo, useRef, useCallback} from "react"; import {menuItem} from "@nextui-org/theme"; import { HTMLNextUIProps, @@ -59,7 +59,6 @@ export function useMenuItem(originalProps: UseMenuItemProps isReadOnly = false, closeOnSelect, onClose, - href, ...otherProps } = props; @@ -68,12 +67,9 @@ export function useMenuItem(originalProps: UseMenuItemProps const domRef = useRef(null); - const Component = as || "li"; + const Component = as || (otherProps?.href ? "a" : "li"); const shouldFilterDOMProps = typeof Component === "string"; - const FragmentWrapper = href ? "a" : Fragment; - const fragmentWrapperProps = href ? {href} : {}; - const {rendered, key} = item; const isDisabledProp = state.disabledKeys.has(key) || originalProps.isDisabled; @@ -198,7 +194,6 @@ export function useMenuItem(originalProps: UseMenuItemProps return { Component, - FragmentWrapper, domRef, slots, classNames, @@ -212,7 +207,6 @@ export function useMenuItem(originalProps: UseMenuItemProps endContent, selectedIcon, disableAnimation, - fragmentWrapperProps, getItemProps, getLabelProps, hideSelectedIcon, diff --git a/packages/components/pagination/__tests__/pagination.test.tsx b/packages/components/pagination/__tests__/pagination.test.tsx index 5de6f4578b..71db770711 100644 --- a/packages/components/pagination/__tests__/pagination.test.tsx +++ b/packages/components/pagination/__tests__/pagination.test.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import {render} from "@testing-library/react"; -import {Pagination, PaginationItem} from "../src"; +import {Pagination} from "../src"; describe("Pagination", () => { it("should render correctly", () => { @@ -37,25 +37,6 @@ describe("Pagination", () => { expect(prevButton).toBeNull(); }); - it("should not have anchor tag when href prop is not passed", () => { - render(); - let anchorTag = document.getElementsByTagName("a")[0]; - - expect(anchorTag).toBeFalsy(); - }); - - it("should have anchor tag when href prop is passed", () => { - const href = "http://www.nextui.org/"; - - render(); - - let anchorTag = document.getElementsByTagName("a")[0]; - - expect(anchorTag).toBeTruthy(); - - expect(anchorTag).toHaveProperty("href", href); - }); - it("should show dots when total is greater than 10", () => { const wrapper = render(); diff --git a/packages/components/pagination/src/pagination-item.tsx b/packages/components/pagination/src/pagination-item.tsx index 03ef05c91c..988e554b23 100644 --- a/packages/components/pagination/src/pagination-item.tsx +++ b/packages/components/pagination/src/pagination-item.tsx @@ -5,14 +5,9 @@ import {usePaginationItem, UsePaginationItemProps} from "./use-pagination-item"; export interface PaginationItemProps extends UsePaginationItemProps {} const PaginationItem = forwardRef<"li", PaginationItemProps>((props, ref) => { - const {Component, FragmentWrapper, fragmentWrapperProps, children, getItemProps} = - usePaginationItem({...props, ref}); + const {Component, children, getItemProps} = usePaginationItem({...props, ref}); - return ( - - {children} - - ); + return {children}; }); PaginationItem.displayName = "NextUI.PaginationItem"; diff --git a/packages/components/pagination/src/use-pagination-item.ts b/packages/components/pagination/src/use-pagination-item.ts index e507d3aaaf..1bef299b98 100644 --- a/packages/components/pagination/src/use-pagination-item.ts +++ b/packages/components/pagination/src/use-pagination-item.ts @@ -2,7 +2,7 @@ import type {Ref} from "react"; import type {HTMLNextUIProps, PropGetter} from "@nextui-org/system"; import type {LinkDOMProps, PressEvent} from "@react-types/shared"; -import {Fragment, useMemo} from "react"; +import {useMemo} from "react"; import {PaginationItemValue} from "@nextui-org/use-pagination"; import {clsx, dataAttr} from "@nextui-org/shared-utils"; import {chain, mergeProps, shouldClientNavigate, useRouter} from "@react-aria/utils"; @@ -64,13 +64,10 @@ export function usePaginationItem(props: UsePaginationItemProps) { } = props; const isLink = !!props?.href; - const Component = as || "li"; + const Component = as || isLink ? "a" : "li"; const shouldFilterDOMProps = typeof Component === "string"; - - const FragmentWrapper = isLink ? "a" : Fragment; - const fragmentWrapperProps = isLink ? {href: props.href} : {}; - const domRef = useDOMRef(ref); + const router = useRouter(); const ariaLabel = useMemo( @@ -132,8 +129,6 @@ export function usePaginationItem(props: UsePaginationItemProps) { return { Component, - FragmentWrapper, - fragmentWrapperProps, children, ariaLabel, isFocused,