JGuang

快捷操作

Speed Dial · Material UI

交互预览
npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

快捷操作

展开一组相关的悬浮操作。

本指南覆盖默认 Emotion 环境的 Material UI Core;扩展包与额外示例按清单单独标注。

使用场景与业务边界

操作需要有意义的标签和真实处理函数;打开菜单不会执行这些操作。操作提示标题通过原生 slotProps.tooltip.title 配置,不用已移除的 tooltipTitle。

原生组成与范围

SpeedDial, SpeedDialAction, SpeedDialIcon

保持 Material UI 原生组合与类型,不替换为 JGuang/Base UI/Radix 同名 API。示例条目不是额外组件。

原生安装与初始化

npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

采用原生 npm 包与 Emotion,不提供虚构的 JGuang UI Registry 地址。将示例放在原生 ThemeProvider 内,按项目选择 CssBaseline 或 ScopedCssBaseline。先检查 React、现有 Provider、锁文件与 SSR 配置;不要覆盖用户文件或忽略 peer 冲突。本批实际验收 React 19.2.8;React 18 及以下须匹配 react-is。完整初始化规则见随附的双语 setup 文档。

关键原生参数

仅解释本指南选出的关键参数,不是平铺的通用 API。原生继承来源、slot 结构、可空值与泛型仍按固定源码保留。

所属组件.属性用途说明声明来源
SpeedDial.ariaLabelSpeedDial 操作菜单所需的原生名称。SpeedDial
SpeedDial.open受控原生可见性,不获取数据或执行操作。SpeedDial
SpeedDial.onOpen原生打开请求,同步所属打开状态。SpeedDial
SpeedDial.onClose原生关闭请求,reason/event 签名因组件不同,宿主须更新 open。SpeedDial
SpeedDialAction.slotProps传给具名原生 slot 的属性,保留 slot 所属组件及回调结构。SpeedDialAction

可运行原生示例

下列机器键只选择示例入口,不会作为通用 variant 属性传入每个组件。原生示例 JSX 与数据保持上游原文;JGuang 编写的验收示例明确标注。

  • 基础快捷操作 · BasicSpeedDial · 上游原生示例
  • 参数演示 · PlaygroundSpeedDial · 上游原生示例
  • 受控快捷操作 · ControlledOpenSpeedDial · 上游原生示例
  • 自定义关闭图标 · OpenIconSpeedDial · 上游原生示例
  • 常驻操作提示 · SpeedDialTooltipOpen · 上游原生示例

真实使用示例

固定版本的未修改原生示例;复制时同时保留所需的局部辅助文件。

import Box from '@mui/material/Box';
import SpeedDial from '@mui/material/SpeedDial';
import SpeedDialIcon from '@mui/material/SpeedDialIcon';
import SpeedDialAction from '@mui/material/SpeedDialAction';
import FileCopyIcon from '@mui/icons-material/FileCopyOutlined';
import SaveIcon from '@mui/icons-material/Save';
import PrintIcon from '@mui/icons-material/Print';
import ShareIcon from '@mui/icons-material/Share';

const actions = [
  { icon: <FileCopyIcon />, name: 'Copy' },
  { icon: <SaveIcon />, name: 'Save' },
  { icon: <PrintIcon />, name: 'Print' },
  { icon: <ShareIcon />, name: 'Share' },
];

export default function BasicSpeedDial() {
  return (
    <Box sx={{ height: 320, transform: 'translateZ(0px)', flexGrow: 1 }}>
      <SpeedDial
        ariaLabel="SpeedDial basic example"
        sx={{ position: 'absolute', bottom: 16, right: 16 }}
        icon={<SpeedDialIcon />}
      >
        {actions.map((action) => (
          <SpeedDialAction
            key={action.name}
            icon={action.icon}
            slotProps={{
              tooltip: {
                title: action.name,
              },
            }}
          />
        ))}
      </SpeedDial>
    </Box>
  );
}

示例依赖边界

@mui/material/Box, @mui/material/SpeedDial, @mui/material/SpeedDialIcon, @mui/material/SpeedDialAction, @mui/icons-material/FileCopyOutlined, @mui/icons-material/Save, @mui/icons-material/Print, @mui/icons-material/Share, react, @mui/material/styles, @mui/material/FormControl, @mui/material/FormControlLabel, @mui/material/FormLabel, @mui/material/Radio, @mui/material/RadioGroup, @mui/material/Switch, @mui/icons-material/Edit, @mui/material/Backdrop

直接导入 Icons/System/Utils 的示例需要匹配 9.4.0 包。局部数据与辅助文件属于示例闭包,不是额外组件。远程图片和模拟操作不提供后端。

固定上游 API 元数据参考

以下表格保留上游元数据,不是重新推断的通用类型体系。条件泛型、继承属性与回调细节以以下源码声明为准。主题默认配置可能覆盖元数据默认值。

SpeedDial

import SpeedDial from '@mui/material/SpeedDial';
import { SpeedDial } from '@mui/material';
属性必需上游元数据类型/约束元数据默认值
ariaLabel是string—
children否node—
classes否object—
direction否'down' | 'left' | 'right' | 'up''up'
FabProps否object{}
hidden否boolfalse
icon否node—
onClose否func—
onOpen否func—
open否bool—
openIcon否node—
slotProps否{ root?: func | object, transition?: func | object }{}
slots否{ root?: elementType, transition?: elementType }{}
sx否Array<func | object | bool> | func | object—
transitionDuration否number | { appear?: number, enter?: number, exit?: number }{ enter: theme.transitions.duration.enteringScreen, exit: theme.transitions.duration.leavingScreen, }

SpeedDialAction

import SpeedDialAction from '@mui/material/SpeedDialAction';
import { SpeedDialAction } from '@mui/material';

原生继承: Tooltip. 父级与 DOM 属性未被伪造为本组件新属性。

属性必需上游元数据类型/约束元数据默认值
classes否object—
delay否number0
icon否node—
id否string—
open否bool—
slotProps否{ fab?: func | object, staticTooltip?: func | object, staticTooltipLabel?: func | object, tooltip?: func | object }{}
slots否{ fab?: elementType, staticTooltip?: elementType, staticTooltipLabel?: elementType, tooltip?: elementType }{}
sx否Array<func | object | bool> | func | object—

SpeedDialIcon

import SpeedDialIcon from '@mui/material/SpeedDialIcon';
import { SpeedDialIcon } from '@mui/material';
属性必需上游元数据类型/约束元数据默认值
classes否object—
icon否node—
openIcon否node—
sx否Array<func | object | bool> | func | object—

原生源码声明

声明与 import 从固定源码提取,不平铺联合类型或外部继承。英文注释/类型属于原始源码参考,不代表上游正文已全文翻译。共享类型仍位于原生包中。

vendor/src/SpeedDial/SpeedDial.d.ts

import * as React from 'react';

import { SxProps } from '@mui/system';

import { Theme } from '../styles';

import { InternalStandardProps as StandardProps } from '../internal';

import { FabProps } from '../Fab';

import { TransitionProps } from '../transitions';

import { SpeedDialClasses } from './speedDialClasses';

import { CreateSlotsAndSlotProps, SlotComponentProps } from '../utils/types';

export type CloseReason = 'toggle' | 'blur' | 'mouseLeave' | 'escapeKeyDown';

export type OpenReason = 'toggle' | 'focus' | 'mouseEnter';

export interface SpeedDialSlots {
  /**
   * The component that renders the root slot.
   * @default 'div'
   */
  root: React.ElementType;
  /**
   * The component that renders the transition.
   * [Follow this guide](/material-ui/transitions/#transition-slots) to learn more about the requirements for this component.
   * @default Zoom
   */
  transition: React.ElementType;
}

export type SpeedDialSlotsAndSlotProps = CreateSlotsAndSlotProps<
  SpeedDialSlots,
  {
    /**
     * Props forwarded to the root slot.
     * By default, the available props are based on div element.
     */
    root: SlotComponentProps<'div', React.HTMLAttributes<HTMLDivElement>, SpeedDialOwnerState>;
    /**
     * Props forwarded to the transition slot.
     * By default, the available props are based on the [Zoom](https://mui.com/material-ui/api/zoom/#props) component.
     */
    transition: SlotComponentProps<
      React.ElementType<TransitionProps>,
      TransitionProps,
      SpeedDialOwnerState
    >;
  }
>;

export interface SpeedDialProps
  extends
    Omit<StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'>, 'slots' | 'slotProps'>,
    SpeedDialSlotsAndSlotProps {
  /**
   * SpeedDialActions to display when the SpeedDial is `open`.
   */
  children?: React.ReactNode;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<SpeedDialClasses> | undefined;
  /**
   * The aria-label of the button element.
   * Also used to provide the `id` for the `SpeedDial` element and its children.
   */
  ariaLabel: string;
  /**
   * The direction the actions open relative to the floating action button.
   * @default 'up'
   */
  direction?: 'up' | 'down' | 'left' | 'right' | undefined;
  /**
   * If `true`, the SpeedDial is hidden.
   * @default false
   */
  hidden?: boolean | undefined;
  /**
   * Props applied to the [`Fab`](https://mui.com/material-ui/api/fab/) element.
   * @default {}
   */
  FabProps?: Partial<FabProps> | undefined;
  /**
   * The icon to display in the SpeedDial Fab. The `SpeedDialIcon` component
   * provides a default Icon with animation.
   */
  icon?: React.ReactNode;
  /**
   * Callback fired when the component requests to be closed.
   *
   * @param {object} event The event source of the callback.
   * @param {string} reason Can be: `"toggle"`, `"blur"`, `"mouseLeave"`, `"escapeKeyDown"`.
   */
  onClose?: ((event: React.SyntheticEvent<{}>, reason: CloseReason) => void) | undefined;
  /**
   * Callback fired when the component requests to be open.
   *
   * @param {object} event The event source of the callback.
   * @param {string} reason Can be: `"toggle"`, `"focus"`, `"mouseEnter"`.
   */
  onOpen?: ((event: React.SyntheticEvent<{}>, reason: OpenReason) => void) | undefined;
  /**
   * If `true`, the component is shown.
   */
  open?: boolean | undefined;
  /**
   * The icon to display in the SpeedDial Fab when the SpeedDial is open.
   */
  openIcon?: React.ReactNode;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
  /**
   * The duration for the transition, in milliseconds.
   * You may specify a single timeout for all transitions, or individually with an object.
   * @default {
   *   enter: theme.transitions.duration.enteringScreen,
   *   exit: theme.transitions.duration.leavingScreen,
   * }
   */
  transitionDuration?: TransitionProps['timeout'] | undefined;
}

export interface SpeedDialOwnerState extends SpeedDialProps {}

export default function SpeedDial(props: SpeedDialProps): React.JSX.Element;

vendor/src/SpeedDialAction/SpeedDialAction.d.ts

import * as React from 'react';

import { SxProps } from '@mui/system';

import { Theme } from '../styles';

import { InternalStandardProps as StandardProps } from '../internal';

import { FabProps } from '../Fab';

import { TooltipProps } from '../Tooltip';

import { SpeedDialActionClasses } from './speedDialActionClasses';

import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';

export interface SpeedDialActionSlots {
  /**
   * The component that renders the fab.
   * @default Fab
   */
  fab?: React.ElementType | undefined;
  /**
   * The component that renders the tooltip.
   * @default Tooltip
   */
  tooltip?: React.ElementType | undefined;
  /**
   * The component that renders the static tooltip.
   * @default 'span'
   */
  staticTooltip?: React.ElementType | undefined;
  /**
   * The component that renders the static tooltip label.
   * @default 'span'
   */
  staticTooltipLabel?: React.ElementType | undefined;
}

export interface SpeedDialActionFabSlotPropsOverrides {}

export interface SpeedDialActionTooltipSlotPropsOverrides {}

export interface SpeedDialActionStaticTooltipSlotPropsOverrides {}

export interface SpeedDialActionStaticTooltipLabelSlotPropsOverrides {}

export type SpeedDialActionSlotsAndSlotProps = CreateSlotsAndSlotProps<
  SpeedDialActionSlots,
  {
    /**
     * Props forwarded to the fab slot.
     * By default, the available props are based on the [Fab](https://mui.com/material-ui/api/fab/#props) component.
     */
    fab: SlotProps<
      React.ElementType<FabProps>,
      SpeedDialActionFabSlotPropsOverrides,
      SpeedDialActionOwnerState
    >;
    /**
     * Props forwarded to the tooltip slot.
     * By default, the available props are based on the [Tooltip](https://mui.com/material-ui/api/tooltip/#props) component.
     */
    tooltip: SlotProps<
      React.ElementType<TooltipProps>,
      SpeedDialActionTooltipSlotPropsOverrides,
      SpeedDialActionOwnerState
    >;
    /**
     * Props forwarded to the static tooltip slot.
     * By default, the available props are based on a span element.
     */
    staticTooltip: SlotProps<
      'span',
      SpeedDialActionStaticTooltipSlotPropsOverrides,
      SpeedDialActionOwnerState
    >;
    /**
     * Props forwarded to the static tooltip label slot.
     * By default, the available props are based on a span element.
     */
    staticTooltipLabel: SlotProps<
      'span',
      SpeedDialActionStaticTooltipLabelSlotPropsOverrides,
      SpeedDialActionOwnerState
    >;
  }
>;

export interface SpeedDialActionProps
  extends
    Omit<StandardProps<Partial<TooltipProps>, 'children'>, 'slotProps' | 'slots'>,
    SpeedDialActionSlotsAndSlotProps {
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<SpeedDialActionClasses> | undefined;
  /**
   * Adds a transition delay, to allow a series of SpeedDialActions to be animated.
   * @default 0
   */
  delay?: number | undefined;
  /**
   * The icon to display in the SpeedDial Fab.
   */
  icon?: React.ReactNode;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
}

export default function SpeedDialAction(props: SpeedDialActionProps): React.JSX.Element;

export interface SpeedDialActionOwnerState extends Omit<
  SpeedDialActionProps,
  'slots' | 'slotProps'
> {}

vendor/src/SpeedDialIcon/SpeedDialIcon.d.ts

import * as React from 'react';

import { SxProps } from '@mui/system';

import { Theme } from '../styles';

import { InternalStandardProps as StandardProps } from '../internal';

import { SpeedDialIconClasses } from './speedDialIconClasses';

export interface SpeedDialIconProps extends StandardProps<
  React.HTMLAttributes<HTMLSpanElement>,
  'children'
> {
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<SpeedDialIconClasses> | undefined;
  /**
   * The icon to display.
   */
  icon?: React.ReactNode;
  /**
   * The icon to display in the SpeedDial Floating Action Button when the SpeedDial is open.
   */
  openIcon?: React.ReactNode;
  /**
   * @ignore
   * If `true`, the component is shown.
   */
  open?: boolean | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
}

declare const SpeedDialIcon: ((props: SpeedDialIconProps) => React.JSX.Element) & {
  muiName: string;
};

安装后验收

执行严格类型检查、生产构建和实际交互。检查键盘标签/焦点、原生支持的禁用/错误/只读语义、深浅色、窄屏和减少动画。按真实宿主数据检查回调,不把复制提示词当作安装完成。初始化工具还需检查服务端 HTML 与无告警水合。

来源与许可

https://github.com/mui/material-ui/tree/809a7717b4c050ba3f69b75300689f07c050a16e

MIT · @mui/material@9.4.0. 保留上游原始内容与许可证。上游完整原文保留于 vendor/docs,不标为全文中文化。