Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/breezy-bobcats-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@nextui-org/pagination": patch
"@nextui-org/listbox": patch
"@nextui-org/menu": patch
---

Reverts the PR-4168 (#4256, #4246, #4244)
34 changes: 0 additions & 34 deletions packages/components/listbox/__tests__/listbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,40 +124,6 @@ describe("Listbox", () => {
expect(() => wrapper.unmount()).not.toThrow();
});

it("should not have anchor tag when href prop is not passed", () => {
render(
<Listbox disallowEmptySelection aria-label="Actions" selectionMode="multiple">
<ListboxItem key="new">New file</ListboxItem>
<ListboxItem key="copy">Copy link</ListboxItem>
<ListboxItem key="edit">Edit file</ListboxItem>
</Listbox>,
);

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(
<Listbox disallowEmptySelection aria-label="Actions" selectionMode="multiple">
<ListboxItem key="new" href={href}>
New file
</ListboxItem>
<ListboxItem key="copy">Copy link</ListboxItem>
<ListboxItem key="edit">Edit file</ListboxItem>
</Listbox>,
);

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();

Expand Down
28 changes: 12 additions & 16 deletions packages/components/listbox/src/listbox-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface ListboxItemProps<T extends object = object>
const ListboxItem = (props: ListboxItemProps) => {
const {
Component,
FragmentWrapper,
rendered,
description,
isSelectable,
Expand All @@ -23,7 +22,6 @@ const ListboxItem = (props: ListboxItemProps) => {
endContent,
hideSelectedIcon,
disableAnimation,
fragmentWrapperProps,
getItemProps,
getLabelProps,
getWrapperProps,
Expand All @@ -47,21 +45,19 @@ const ListboxItem = (props: ListboxItemProps) => {

return (
<Component {...getItemProps()}>
<FragmentWrapper {...fragmentWrapperProps}>
{startContent}
{description ? (
<div {...getWrapperProps()}>
<span {...getLabelProps()}>{rendered}</span>
<span {...getDescriptionProps()}>{description}</span>
</div>
) : (
{startContent}
{description ? (
<div {...getWrapperProps()}>
<span {...getLabelProps()}>{rendered}</span>
)}
{isSelectable && !hideSelectedIcon && (
<span {...getSelectedIconProps()}>{selectedContent}</span>
)}
{endContent}
</FragmentWrapper>
<span {...getDescriptionProps()}>{description}</span>
</div>
) : (
<span {...getLabelProps()}>{rendered}</span>
)}
{isSelectable && !hideSelectedIcon && (
<span {...getSelectedIconProps()}>{selectedContent}</span>
)}
{endContent}
</Component>
);
};
Expand Down
10 changes: 2 additions & 8 deletions packages/components/listbox/src/use-listbox-item.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -50,7 +50,6 @@ export function useListboxItem<T extends object>(originalProps: UseListboxItemPr
shouldHighlightOnFocus,
hideSelectedIcon = false,
isReadOnly = false,
href,
...otherProps
} = props;

Expand All @@ -59,12 +58,9 @@ export function useListboxItem<T extends object>(originalProps: UseListboxItemPr

const domRef = useRef<HTMLLIElement>(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;
Expand Down Expand Up @@ -173,7 +169,6 @@ export function useListboxItem<T extends object>(originalProps: UseListboxItemPr

return {
Component,
FragmentWrapper,
domRef,
slots,
classNames,
Expand All @@ -187,7 +182,6 @@ export function useListboxItem<T extends object>(originalProps: UseListboxItemPr
selectedIcon,
hideSelectedIcon,
disableAnimation,
fragmentWrapperProps,
getItemProps,
getLabelProps,
getWrapperProps,
Expand Down
40 changes: 0 additions & 40 deletions packages/components/menu/__tests__/menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,46 +125,6 @@ describe("Menu", () => {
expect(() => wrapper.unmount()).not.toThrow();
});

it("should not have anchor tag when href prop is not passed", () => {
render(
<Menu disallowEmptySelection aria-label="Actions" selectionMode="multiple">
<MenuItem key="new">New file</MenuItem>
<MenuItem key="copy">Copy link</MenuItem>
<MenuItem key="edit">Edit file</MenuItem>
<MenuItem key="delete" color="danger">
Delete file
</MenuItem>
</Menu>,
);

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(
<Menu disallowEmptySelection aria-label="Actions" selectionMode="multiple">
<MenuItem key="new" href={href}>
New file
</MenuItem>
<MenuItem key="copy">Copy link</MenuItem>
<MenuItem key="edit">Edit file</MenuItem>
<MenuItem key="delete" color="danger">
Delete file
</MenuItem>
</Menu>,
);

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();

Expand Down
30 changes: 13 additions & 17 deletions packages/components/menu/src/menu-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface MenuItemProps<T extends object = object>
const MenuItem = (props: MenuItemProps) => {
const {
Component,
FragmentWrapper,
slots,
classNames,
rendered,
Expand All @@ -26,7 +25,6 @@ const MenuItem = (props: MenuItemProps) => {
endContent,
disableAnimation,
hideSelectedIcon,
fragmentWrapperProps,
getItemProps,
getLabelProps,
getDescriptionProps,
Expand All @@ -50,22 +48,20 @@ const MenuItem = (props: MenuItemProps) => {

return (
<Component {...getItemProps()}>
<FragmentWrapper {...fragmentWrapperProps}>
{startContent}
{description ? (
<div className={slots.wrapper({class: classNames?.wrapper})}>
<span {...getLabelProps()}>{rendered}</span>
<span {...getDescriptionProps()}>{description}</span>
</div>
) : (
{startContent}
{description ? (
<div className={slots.wrapper({class: classNames?.wrapper})}>
<span {...getLabelProps()}>{rendered}</span>
)}
{shortcut && <kbd {...getKeyboardShortcutProps()}>{shortcut}</kbd>}
{isSelectable && !hideSelectedIcon && (
<span {...getSelectedIconProps()}>{selectedContent}</span>
)}
{endContent}
</FragmentWrapper>
<span {...getDescriptionProps()}>{description}</span>
</div>
) : (
<span {...getLabelProps()}>{rendered}</span>
)}
{shortcut && <kbd {...getKeyboardShortcutProps()}>{shortcut}</kbd>}
{isSelectable && !hideSelectedIcon && (
<span {...getSelectedIconProps()}>{selectedContent}</span>
)}
{endContent}
</Component>
);
};
Expand Down
10 changes: 2 additions & 8 deletions packages/components/menu/src/use-menu-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -59,7 +59,6 @@ export function useMenuItem<T extends object>(originalProps: UseMenuItemProps<T>
isReadOnly = false,
closeOnSelect,
onClose,
href,
...otherProps
} = props;

Expand All @@ -68,12 +67,9 @@ export function useMenuItem<T extends object>(originalProps: UseMenuItemProps<T>

const domRef = useRef<HTMLLIElement>(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;
Expand Down Expand Up @@ -198,7 +194,6 @@ export function useMenuItem<T extends object>(originalProps: UseMenuItemProps<T>

return {
Component,
FragmentWrapper,
domRef,
slots,
classNames,
Expand All @@ -212,7 +207,6 @@ export function useMenuItem<T extends object>(originalProps: UseMenuItemProps<T>
endContent,
selectedIcon,
disableAnimation,
fragmentWrapperProps,
getItemProps,
getLabelProps,
hideSelectedIcon,
Expand Down
21 changes: 1 addition & 20 deletions packages/components/pagination/__tests__/pagination.test.tsx
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -37,25 +37,6 @@ describe("Pagination", () => {
expect(prevButton).toBeNull();
});

it("should not have anchor tag when href prop is not passed", () => {
render(<PaginationItem />);
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(<PaginationItem href={href} />);

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(<Pagination total={10} />);

Expand Down
9 changes: 2 additions & 7 deletions packages/components/pagination/src/pagination-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Component {...getItemProps()}>
<FragmentWrapper {...fragmentWrapperProps}>{children}</FragmentWrapper>
</Component>
);
return <Component {...getItemProps()}>{children}</Component>;
});

PaginationItem.displayName = "NextUI.PaginationItem";
Expand Down
11 changes: 3 additions & 8 deletions packages/components/pagination/src/use-pagination-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -132,8 +129,6 @@ export function usePaginationItem(props: UsePaginationItemProps) {

return {
Component,
FragmentWrapper,
fragmentWrapperProps,
children,
ariaLabel,
isFocused,
Expand Down