/* * Copyright 2022 Palantir Technologies, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import classNames from "classnames"; import { createElement, forwardRef } from "react"; import { CaretRightIcon, SmallTickIcon } from "@blueprintjs/icons"; import { Classes } from "../../common"; import { type ActionProps, DISPLAYNAME_PREFIX, removeNonHTMLProps } from "../../common/props"; import { clickElementOnKeyPress } from "../../common/utils"; import { Icon } from "../icon/icon"; import type { PopoverProps } from "../popover/popoverProps"; import type { MiddlewareConfig } from "../popover-next/middlewareTypes"; import { PopoverNext } from "../popover-next/popoverNext"; import { popoverPropsToNextProps } from "../popover-next/popoverNextMigrationUtils"; import { Text } from "../text/text"; import { Menu, type MenuProps } from "./menu"; /** * Note that the HTML attributes supported by this component are spread to the nested `` element, while the * `ref` is attached to the root `
  • ` element. This is an unfortunate quirk in the API which we keep around * for backwards-compatibility. */ export interface MenuItemProps extends ActionProps, React.AnchorHTMLAttributes, React.RefAttributes { /** Item text, required for usability. */ text: React.ReactNode; /** * Whether this item should appear _active_, often useful to * indicate keyboard focus. Note that this is distinct from _selected_ * appearance, which has its own prop. */ active?: boolean; /** * Children of this component will be rendered in a _submenu_ * that appears in a popover when hovering or clicking on this item. * * Use `text` prop for the content of the menu item itself. */ children?: React.ReactNode; /** * Whether this menu item is non-interactive. Enabling this prop will ignore `href`, `tabIndex`, * and mouse event handlers (in particular click, down, enter, leave). */ disabled?: boolean; /** * Right-aligned label text content, useful for displaying hotkeys. * * This prop actually supports JSX elements, but TypeScript will throw an error because * `HTMLAttributes` only allows strings. Use `labelElement` to supply a JSX element in TypeScript. */ label?: string; /** * A space-delimited list of class names to pass along to the right-aligned label wrapper element. */ labelClassName?: string; /** * Right-aligned label content, useful for displaying hotkeys. */ labelElement?: React.ReactNode; /** * Changes the ARIA `role` property structure of this MenuItem to accomodate for various * different `role`s of the parent Menu `ul` element. * * If `menuitem`, role structure becomes: * * `
  • ` * * which is proper role structure for a `