Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

UIT-146: Fix keyboard navigation on sidebar bookmarks (#85963)

Will Frya80b931e2dc7
diff --git a/frontend/src/metabase/common/components/Sortable/Sortable.tsx b/frontend/src/metabase/common/components/Sortable/Sortable.tsx
index 9be9d69b9ac..ebdb3db58af 100644
--- a/frontend/src/metabase/common/components/Sortable/Sortable.tsx
+++ b/frontend/src/metabase/common/components/Sortable/Sortable.tsx
@@ -42,7 +42,7 @@ export function Sortable({
className,
style,
draggingStyle,
- role = "button",
+ role,
}: SortableProps) {
const dragHandleRef = useRef(null);
@@ -68,6 +68,10 @@ export function Sortable({
const childrenAsFunction = typeof children === "function";
+ // Without a keyboard sensor, these would make the wrapper a tab stop that does nothing
+ const dragAttributes =
+ listeners?.onKeyDown && !disabled ? attributes : undefined;
+
return (
<Component
className={cx(className, { [S.dragging]: isDragging })}
@@ -79,9 +83,9 @@ export function Sortable({
}}
data-is-dragging={isDragging}
ref={setNodeRef}
- {...(disabled ? {} : attributes)}
+ {...dragAttributes}
{...(!childrenAsFunction && listeners)}
- role={role}
+ role={role ?? dragAttributes?.role}
>
{childrenAsFunction
? children({ dragHandleRef, dragHandleListeners: listeners })
diff --git a/frontend/src/metabase/common/components/Sortable/Sortable.unit.spec.tsx b/frontend/src/metabase/common/components/Sortable/Sortable.unit.spec.tsx
new file mode 100644
index 00000000000..ec806642173
--- /dev/null
+++ b/frontend/src/metabase/common/components/Sortable/Sortable.unit.spec.tsx
@@ -0,0 +1,60 @@
+import {
+ DndContext,
+ KeyboardSensor,
+ PointerSensor,
+ useSensor,
+} from "@dnd-kit/core";
+import { SortableContext } from "@dnd-kit/sortable";
+
+import { render, screen } from "__support__/ui";
+
+import { Sortable } from "./Sortable";
+
+describe("Sortable", () => {
+ it("is a tab stop when it can be dragged with the keyboard", () => {
+ render(<SortableInContext withKeyboard />);
+
+ expect(screen.getByRole("button")).toHaveAttribute("tabindex", "0");
+ });
+
+ it("is not a tab stop when it can't be dragged with the keyboard", () => {
+ render(<SortableInContext withKeyboard={false} />);
+
+ expect(screen.queryByRole("button")).not.toBeInTheDocument();
+ expect(screen.getByText("Item").parentElement).not.toHaveAttribute(
+ "tabindex",
+ );
+ });
+
+ it("is not a tab stop when it's disabled, even with a keyboard sensor", () => {
+ render(<SortableInContext withKeyboard disabled />);
+
+ expect(screen.queryByRole("button")).not.toBeInTheDocument();
+ expect(screen.getByText("Item").parentElement).not.toHaveAttribute(
+ "tabindex",
+ );
+ });
+});
+
+function SortableInContext({
+ withKeyboard,
+ disabled,
+}: {
+ withKeyboard: boolean;
+ disabled?: boolean;
+}) {
+ const pointerSensor = useSensor(PointerSensor);
+ const keyboardSensor = useSensor(KeyboardSensor);
+
+ return (
+ <DndContext
+ sensors={withKeyboard ? [pointerSensor, keyboardSensor] : [pointerSensor]}
+ >
+ <SortableContext items={["item"]}>
+ <Sortable id="item" disabled={disabled}>
+ <span>Item</span>
+ </Sortable>
+ </SortableContext>
+ </DndContext>
+ );
+}
diff --git a/frontend/src/metabase/common/components/tree/TreeNode.tsx b/frontend/src/metabase/common/components/tree/TreeNode.tsx
index 8b1e5c76cc2..965b9f09b7f 100644
--- a/frontend/src/metabase/common/components/tree/TreeNode.tsx
+++ b/frontend/src/metabase/common/components/tree/TreeNode.tsx
@@ -85,22 +85,18 @@ function ExpandToggleIcon({
type NameContainerProps = BoxProps & ElementProps<"div">;
-// The sidebar wraps it in a Tooltip, which needs the ref
-const NameContainer = React.forwardRef<HTMLDivElement, NameContainerProps>(
- function NameContainer({ className, ...props }, ref) {
- return (
- <Box
- ref={ref}
- className={cx(S.name, className)}
- flex={1}
- py="sm"
- pr="sm"
- pl="xxs"
- {...props}
- />
- );
- },
-);
+function NameContainer({ className, ...props }: NameContainerProps) {
+ return (
+ <Box
+ className={cx(S.name, className)}
+ flex={1}
+ py="sm"
+ pr="sm"
+ pl="xxs"
+ {...props}
+ />
+ );
+}
type IconContainerProps = FlexProps & {
transparent?: boolean;
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.module.css b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.module.css
index debd46b42e3..11811ddbbf4 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.module.css
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.module.css
@@ -5,7 +5,10 @@
}
.bookmark:hover .removeButton,
-.bookmark:focus-within .removeButton,
-:focus .bookmark .removeButton {
+.bookmark:focus-within .removeButton {
opacity: 0.5;
}
+
+.bookmark .removeButton:focus-visible {
+ opacity: 1;
+}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx
index 9d27de1532a..f4ac718039f 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx
@@ -9,7 +9,13 @@ import {
verticalListSortingStrategy,
} from "@dnd-kit/sortable";
import cx from "classnames";
-import { useCallback, useEffect, useState } from "react";
+import {
+ type MouseEvent,
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
import { t } from "ttag";
import { useDeleteBookmarkMutation } from "metabase/api";
@@ -22,6 +28,7 @@ import { useGetIcon } from "metabase/hooks/use-icon";
import { useSelector } from "metabase/redux";
import { Icon, Tooltip } from "metabase/ui";
import * as Urls from "metabase/urls";
+import { isFocusVisible } from "metabase/utils/dom";
import type { Bookmark } from "metabase-types/api";
import { SidebarHeading } from "../../Sidebar";
@@ -52,7 +59,11 @@ interface BookmarkItemProps {
isSorting: boolean;
selectedItem?: SelectedItem;
onSelect: () => void;
- onDeleteBookmark: (bookmark: Bookmark) => void;
+ onDeleteBookmark: (
+ bookmark: Bookmark,
+ index: number,
+ button: HTMLButtonElement,
+ ) => void;
}
function isBookmarkSelected(bookmark: Bookmark, selectedItem?: SelectedItem) {
@@ -78,6 +89,7 @@ function getBookmarkModel(bookmark: Bookmark) {
const BookmarkItem = ({
bookmark,
+ index,
isDraggable,
isSorting,
selectedItem,
@@ -98,7 +110,8 @@ const BookmarkItem = ({
},
{ isTenantUser },
);
- const onRemove = () => onDeleteBookmark(bookmark);
+ const onRemove = (event: MouseEvent<HTMLButtonElement>) =>
+ onDeleteBookmark(bookmark, index, event.currentTarget);
const iconName = isSelected ? "bookmark_filled" : "bookmark";
@@ -113,14 +126,17 @@ const BookmarkItem = ({
isDraggable={isDraggable}
onClick={onSelect}
right={
- <button
- className={cx(S.removeButton, CS.cursorPointer)}
- onClick={onRemove}
- >
- <Tooltip label={t`Remove bookmark`} position="bottom">
+ <Tooltip label={t`Remove bookmark`} position="right">
+ <button
+ className={cx(S.removeButton, CS.cursorPointer)}
+ aria-label={t`Remove bookmark`}
+ // The tooltip repeats the accessible name, so it mustn't also describe it.
+ aria-describedby={undefined}
+ onClick={onRemove}
+ >
<Icon name={iconName} />
- </Tooltip>
- </button>
+ </button>
+ </Tooltip>
}
>
{bookmark.name}
@@ -138,8 +154,19 @@ const BookmarkList = ({
initialState,
}: CollectionSidebarBookmarksProps) => {
const [deleteBookmark] = useDeleteBookmarkMutation();
- const onDeleteBookmark = ({ item_id, type }: Bookmark) =>
+ const listRef = useRef<HTMLUListElement>(null);
+ const onDeleteBookmark = (
+ { item_id, type }: Bookmark,
+ index: number,
+ button: HTMLButtonElement,
+ ) => {
+ // Removing the row takes the focused button with it, which drops focus to the page
+ if (isFocusVisible(button)) {
+ const links = listRef.current?.querySelectorAll("a");
+ (links?.[index + 1] ?? links?.[index - 1])?.focus();
+ }
deleteBookmark({ id: item_id, type });
+ };
const [orderedBookmarks, setOrderedBookmarks] = useState(bookmarks);
const [isSorting, setIsSorting] = useState(false);
@@ -189,13 +216,13 @@ const BookmarkList = ({
items={bookmarkIds ?? []}
strategy={verticalListSortingStrategy}
>
- <ul>
+ <ul ref={listRef}>
{orderedBookmarks.map((bookmark, index) => (
<BookmarkItem
bookmark={bookmark}
isDraggable={orderedBookmarks.length > 1}
isSorting={isSorting}
- key={index}
+ key={bookmark.id}
index={index}
selectedItem={selectedItem}
onSelect={onSelect}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.unit.spec.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.unit.spec.tsx
index 2ed811ece5f..d93ffb11059 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.unit.spec.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.unit.spec.tsx
@@ -1,7 +1,9 @@
+import userEvent from "@testing-library/user-event";
import type { ComponentProps } from "react";
import { times } from "underscore";
import { setupEnterprisePlugins } from "__support__/enterprise";
+import { setupDeleteBookmarkEndpoint } from "__support__/server-mocks";
import { mockSettings } from "__support__/settings";
import { createMockState } from "__support__/state";
import { renderWithProviders, screen, within } from "__support__/ui";
@@ -92,6 +94,116 @@ describe("BookmarkList", () => {
).toBeInTheDocument();
});
+ describe("keyboard navigation (#85912)", () => {
+ const LONG_NAME = "A bookmark with a name long enough to be truncated";
+
+ it("only stops on each bookmark's link and remove button", async () => {
+ renderWithProviders(
+ <BookmarkList {...mockProps} bookmarks={createBookmarks(2)} />,
+ );
+
+ const [firstRemoveButton, secondRemoveButton] = screen.getAllByRole(
+ "button",
+ { name: "Remove bookmark" },
+ );
+
+ await userEvent.tab(); // the section header
+ await userEvent.tab();
+ expect(screen.getByRole("link", { name: /Bookmark 1/ })).toHaveFocus();
+ await userEvent.tab();
+ expect(firstRemoveButton).toHaveFocus();
+ await userEvent.tab();
+ expect(screen.getByRole("link", { name: /Bookmark 2/ })).toHaveFocus();
+ await userEvent.tab();
+ expect(secondRemoveButton).toHaveFocus();
+ });
+
+ it("shows the full name of a long bookmark when its link has focus", async () => {
+ renderWithProviders(
+ <BookmarkList
+ {...mockProps}
+ bookmarks={[createMockBookmark({ name: LONG_NAME })]}
+ />,
+ );
+
+ await userEvent.tab(); // the section header
+ await userEvent.tab();
+
+ expect(await screen.findByRole("tooltip")).toHaveTextContent(LONG_NAME);
+ expect(screen.getByRole("link")).not.toHaveAttribute("aria-describedby");
+ });
+
+ it("shows the remove button's tooltip when it has focus", async () => {
+ renderWithProviders(
+ <BookmarkList {...mockProps} bookmarks={createBookmarks(1)} />,
+ );
+
+ await userEvent.tab(); // the section header
+ await userEvent.tab();
+ await userEvent.tab();
+
+ expect(
+ screen.getByRole("button", { name: "Remove bookmark" }),
+ ).toHaveFocus();
+ expect(await screen.findByRole("tooltip")).toHaveTextContent(
+ "Remove bookmark",
+ );
+ });
+
+ it("moves focus to the next bookmark when one is removed with the keyboard", async () => {
+ const bookmarks = createBookmarks(2);
+ setupDeleteBookmarkEndpoint(bookmarks[0]);
+ const { rerender } = renderWithProviders(
+ <BookmarkList {...mockProps} bookmarks={bookmarks} />,
+ );
+
+ await userEvent.tab(); // the section header
+ await userEvent.tab();
+ await userEvent.tab();
+ await userEvent.keyboard("{Enter}");
+
+ const nextLink = screen.getByRole("link", { name: /Bookmark 2/ });
+ expect(nextLink).toHaveFocus();
+
+ rerender(<BookmarkList {...mockProps} bookmarks={[bookmarks[1]]} />);
+
+ expect(nextLink).toHaveFocus();
+ });
+
+ it("moves focus to the previous bookmark when the last one is removed with the keyboard", async () => {
+ const bookmarks = createBookmarks(2);
+ setupDeleteBookmarkEndpoint(bookmarks[1]);
+ renderWithProviders(
+ <BookmarkList {...mockProps} bookmarks={bookmarks} />,
+ );
+
+ await userEvent.tab(); // the section header
+ await userEvent.tab();
+ await userEvent.tab();
+ await userEvent.tab();
+ await userEvent.tab();
+ await userEvent.keyboard("{Enter}");
+
+ expect(screen.getByRole("link", { name: /Bookmark 1/ })).toHaveFocus();
+ });
+
+ it("doesn't move focus to another bookmark when one is removed with the mouse", async () => {
+ const bookmarks = createBookmarks(2);
+ setupDeleteBookmarkEndpoint(bookmarks[0]);
+ renderWithProviders(
+ <BookmarkList {...mockProps} bookmarks={bookmarks} />,
+ );
+
+ await userEvent.click(
+ screen.getAllByRole("button", { name: "Remove bookmark" })[0],
+ );
+
+ expect(
+ screen.getByRole("link", { name: /Bookmark 2/ }),
+ ).not.toHaveFocus();
+ });
+ });
+
describe("collection bookmark icons (enterprise)", () => {
it.each([
{
@@ -118,11 +230,8 @@ describe("BookmarkList", () => {
{ storeInitialState: enterpriseState },
);
- const row = screen.getByText(name).closest("a");
- expect(
- // Unjustified type cast. FIXME
- within(row as HTMLElement).getByLabelText(`${icon} icon`),
- ).toBeInTheDocument();
+ const row = screen.getByRole("link", { name: new RegExp(name) });
+ expect(within(row).getByLabelText(`${icon} icon`)).toBeInTheDocument();
},
);
});
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx
index 2224629eea8..7c7a9a80ae9 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx
@@ -18,7 +18,7 @@ import { Flex, Icon } from "metabase/ui";
import * as Urls from "metabase/urls";
import type { Collection } from "metabase-types/api";
-import { SidebarItemName } from "./SidebarItemName";
+import { LongItemNameTooltip, SidebarItemName } from "./SidebarItemName";
import S from "./SidebarItems.module.css";
type DroppableProps = {
@@ -132,30 +132,32 @@ const SidebarCollectionLink = forwardRef<HTMLLIElement, Props>(
size={12}
/>
</TreeNode.ExpandToggleButton>
- {nonNavigable ? (
- <Flex
- className={CS.cursorPointer}
- align="center"
- w="100%"
- miw={0}
- onKeyDown={onKeyDown}
- >
- {content}
- </Flex>
- ) : (
- <Flex
- component={ForwardRefLink}
- className={S.link}
- align="center"
- w="100%"
- miw={0}
- to={url}
- onClick={onSelect}
- onKeyDown={onKeyDown}
- >
- {content}
- </Flex>
- )}
+ <LongItemNameTooltip itemName={collection.name}>
+ {nonNavigable ? (
+ <Flex
+ className={CS.cursorPointer}
+ align="center"
+ w="100%"
+ miw={0}
+ onKeyDown={onKeyDown}
+ >
+ {content}
+ </Flex>
+ ) : (
+ <Flex
+ component={ForwardRefLink}
+ className={S.link}
+ align="center"
+ w="100%"
+ miw={0}
+ to={url}
+ onClick={onSelect}
+ onKeyDown={onKeyDown}
+ >
+ {content}
+ </Flex>
+ )}
+ </LongItemNameTooltip>
</TreeNode.Root>
);
},
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.unit.spec.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.unit.spec.tsx
new file mode 100644
index 00000000000..2e73c65172a
--- /dev/null
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.unit.spec.tsx
@@ -0,0 +1,29 @@
+import userEvent from "@testing-library/user-event";
+
+import { renderWithProviders, screen } from "__support__/ui";
+
+import { DroppableSidebarCollectionLink } from "./SidebarCollectionLink";
+
+describe("DroppableSidebarCollectionLink", () => {
+ it("shows the full name of a long collection when its link has focus (#85912)", async () => {
+ const name = "A collection with a name long enough to be truncated";
+
+ renderWithProviders(
+ <DroppableSidebarCollectionLink
+ item={{ id: 1, name, icon: "folder" }}
+ depth={0}
+ hasChildren
+ isExpanded={false}
+ isSelected={false}
+ onToggleExpand={jest.fn<void, []>()}
+ />,
+ { withDND: true },
+ );
+
+ await userEvent.tab(); // the expand toggle
+ await userEvent.tab();
+
+ expect(screen.getByRole("link", { name: new RegExp(name) })).toHaveFocus();
+ expect(await screen.findByRole("tooltip")).toHaveTextContent(name);
+ });
+});
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItemName.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItemName.tsx
index 011480906fa..3c03abfc532 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItemName.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItemName.tsx
@@ -1,4 +1,5 @@
import cx from "classnames";
+import { type ReactElement, cloneElement } from "react";
import { TreeNode } from "metabase/common/components/tree/TreeNode";
import CS from "metabase/css/core/index.css";
@@ -6,6 +7,35 @@ import { type BoxProps, Tooltip } from "metabase/ui";
const ITEM_NAME_LENGTH_TOOLTIP_THRESHOLD = 35;
+function isLongItemName(itemName: string) {
+ return itemName.length >= ITEM_NAME_LENGTH_TOOLTIP_THRESHOLD;
+}
+
+interface LongItemNameTooltipProps {
+ itemName: string;
+ children: ReactElement<{ "aria-describedby"?: string }>;
+}
+
+/**
+ * Shows the full name of an item with a long name, which `SidebarItemName`
+ * truncates, and renders just `children` for any other name. Wrap the element
+ * that takes keyboard focus, so the tooltip also opens on focus.
+ */
+export function LongItemNameTooltip({
+ itemName,
+ children,
+}: LongItemNameTooltipProps) {
+ if (!isLongItemName(itemName)) {
+ return children;
+ }
+ return (
+ <Tooltip label={itemName} withArrow maw="65ch">
+ {/* The tooltip repeats the accessible name, so it mustn't also describe it. */}
+ {cloneElement(children, { "aria-describedby": undefined })}
+ </Tooltip>
+ );
+}
+
interface SidebarItemNameProps extends BoxProps {
children: string;
}
@@ -15,26 +45,17 @@ export function SidebarItemName({
className,
...props
}: SidebarItemNameProps) {
- if (itemName.length >= ITEM_NAME_LENGTH_TOOLTIP_THRESHOLD) {
- return (
- <Tooltip label={itemName} withArrow maw="65ch">
- <TreeNode.NameContainer
- className={cx(
- CS.textNoWrap,
- CS.overflowHidden,
- CS.textEllipsis,
- className,
- )}
- miw={0}
- {...props}
- >
- {itemName}
- </TreeNode.NameContainer>
- </Tooltip>
- );
- }
+ const isLongName = isLongItemName(itemName);
+
return (
- <TreeNode.NameContainer className={className} {...props}>
+ <TreeNode.NameContainer
+ className={cx(
+ isLongName && [CS.textNoWrap, CS.overflowHidden, CS.textEllipsis],
+ className,
+ )}
+ miw={isLongName ? 0 : undefined}
+ {...props}
+ >
{itemName}
</TreeNode.NameContainer>
);
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.module.css b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.module.css
index 70b468b3cce..fe122e73872 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.module.css
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.module.css
@@ -2,7 +2,7 @@
padding-left: calc(var(--tree-depth) * 1rem);
color: var(--mb-color-text-primary);
- &:focus-within {
+ &:has(.link:focus, .button:focus) {
outline: 2px solid var(--mb-color-input-focus);
outline-offset: -2px;
}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarLink.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarLink.tsx
index dd0ca73acfa..16550c261aa 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarLink.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarLink.tsx
@@ -11,7 +11,7 @@ import CS from "metabase/css/core/index.css";
import { Flex, Icon, type IconProps } from "metabase/ui";
import type { IconName } from "metabase-types/api";
-import { SidebarItemName } from "./SidebarItemName";
+import { LongItemNameTooltip, SidebarItemName } from "./SidebarItemName";
import S from "./SidebarItems.module.css";
export interface SidebarLinkProps {
@@ -101,35 +101,37 @@ export function SidebarLink({
{...props}
>
{isValidElement(left) && <div>{left}</div>}
- {url ? (
- <Flex
- component={ForwardRefLink}
- className={S.link}
- align="center"
- w="100%"
- miw={0}
- to={url}
- target={target}
- rel={rel}
- onClick={onClick}
- >
- {content}
- </Flex>
- ) : (
- <Flex
- component="button"
- className={cx(S.button, CS.cursorPointer)}
- align="center"
- w="100%"
- miw={0}
- c="inherit"
- fw={700}
- ta="start"
- onClick={onClick}
- >
- {content}
- </Flex>
- )}
+ <LongItemNameTooltip itemName={children}>
+ {url ? (
+ <Flex
+ component={ForwardRefLink}
+ className={S.link}
+ align="center"
+ w="100%"
+ miw={0}
+ to={url}
+ target={target}
+ rel={rel}
+ onClick={onClick}
+ >
+ {content}
+ </Flex>
+ ) : (
+ <Flex
+ component="button"
+ className={cx(S.button, CS.cursorPointer)}
+ align="center"
+ w="100%"
+ miw={0}
+ c="inherit"
+ fw={700}
+ ta="start"
+ onClick={onClick}
+ >
+ {content}
+ </Flex>
+ )}
+ </LongItemNameTooltip>
{isValidElement(right) && <div>{right}</div>}
</TreeNode.Root>
);
diff --git a/frontend/test/__support__/server-mocks/bookmark.ts b/frontend/test/__support__/server-mocks/bookmark.ts
index 09b9efbbf56..bee842346e4 100644
--- a/frontend/test/__support__/server-mocks/bookmark.ts
+++ b/frontend/test/__support__/server-mocks/bookmark.ts
@@ -6,6 +6,13 @@ export function setupBookmarksEndpoints(bookmarks: Bookmark[]) {
fetchMock.get("path:/api/bookmark", bookmarks);
}
+export function setupDeleteBookmarkEndpoint({
+ item_id,
+ type,
+}: Pick<Bookmark, "item_id" | "type">) {
+ fetchMock.delete(`path:/api/bookmark/${type}/${item_id}`, 204);
+}
+
export function setupBookmarksEndpointsWithError({
error,
status = 500,