JGuang

FloatButton

FloatButton · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

FloatButton

A button that floats at the top of the page.

When To Use

  • For global functionality on the site.
  • Buttons that can be seen wherever you browse.

Examples

  • Basic · basic

  • Type · type

  • Shape · shape

  • Content · content

  • FloatButton with tooltip · tooltip

  • FloatButton Group · group

  • Menu mode · group-menu

  • Controlled mode · controlled

  • placement · placement

  • draggable · draggable

  • BackTop · back-top

  • Progress ring · progress-ring

  • badge · badge

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

This component is available since antd@5.0.0.

common API

PropertyDescriptionTypeDefaultVersionGlobal Config
iconSet the icon component of buttonReactNode-FloatButton: ×, BackTop: 5.27.0
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
contentText and otherReactNode-×
descriptionPlease use content insteadReactNode-×
tooltipThe text shown in the tooltipReactNode | TooltipProps-TooltipProps: 5.25.0×
typeSetting button typedefault | primarydefault×
shapeSetting button shapecircle | squarecircle×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
onClickSet the handler to handle click event(event) => void-×
hrefThe target of hyperlinkstring-×
targetSpecifies where to display the linked URLstring-×
htmlTypeSet the original html type of button, see: MDNsubmit | reset | buttonbutton5.21.0×
badgeAttach Badge to FloatButton. status and other props related are not supported.BadgeProps-5.4.0×
disabledWhether the button is disabledboolean-6.4.0×

FloatButton.Group

PropertyDescriptionTypeDefaultVersionGlobal Config
openWhether the menu is visible or not, use it with triggerboolean-×
closeIconCustomize close button iconReact.ReactNode<CloseOutlined />5.16.0
placementCustomize menu animation placementtop | left | right | bottomtop5.21.0×
shapeSetting button shape of childrencircle | squarecircle×
triggerWhich action can trigger menu open/closeclick | hover-×
onOpenChangeCallback executed when active menu is changed, use it with trigger(open: boolean) => void-×
onClickSet the handler to handle click event (only work in Menu mode)(event) => void-5.3.0×

FloatButton.BackTop

PropertyDescriptionTypeDefaultVersion
durationTime to return to top (ms). This property is ignored when enables reduced motion (prefers-reduced-motion: reduce)number450
showProgressShow the current scroll progress ring around the BackTop button edgebooleanfalse6.6.0
targetSpecifies the scrollable area dom node() => HTMLElement() => window
visibilityHeightThe BackTop button will not show until the scroll height reaches this valuenumber400
onClickA callback function, which can be executed when you click the button() => void-

Semantic DOM

FloatButton

Semantic nodeNative descriptionVersion
rootRoot element with float button base styles, shape size, type theme, fixed positioning, z-index, shadow, spacing and other container styles—
iconIcon element with button icon size, color, line height, alignment and other icon display styles—
contentContent element with button text content font size, color, alignment, line wrap and other text display styles—

Semantic description source: vendor/components/float-button/demo/_semantic.tsx

FloatButton.Group

Semantic nodeNative descriptionVersion
rootRoot element with float button group container styles, fixed positioning, z-index, padding, gap, direction mode and other combined layout styles—
listList element with button group list flex layout, border radius, shadow, animation transition, vertical alignment and other list container styles—
itemItem element with individual float button styles, size, shape, type, state, icon content and other button base styles—
itemIconItem icon element with float button icon size, color, alignment and other icon display styles—
itemContentItem content element with float button text content, badge, description and other content area styles—
triggerTrigger element with menu mode trigger button styles, shape, icon, hover state, expand/collapse state and other interaction styles—
triggerIconTrigger icon element with trigger button icon styles, rotation animation, toggle state and other icon interaction styles—
triggerContentTrigger content element with trigger button content area text, identifier, state indicator and other content styles—

Semantic description source: vendor/components/float-button/demo/_semantic_group.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

Native ComponentToken declares no directly extractable own fields. Shared tokens and inheritance are defined by the declarations below.

Declaration source: vendor/components/float-button/style/index.ts

import { initFadeMotion } from '../../style/motion/fade';

import type { FullToken, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

import genFloatButtonStyle from './button';

import genGroupStyle from './group';

/** Component only token. Which will handle additional calculation of alias token */
export type ComponentToken = object;

/**
 * @desc FloatButton 组件的 Token
 * @descEN Token for FloatButton component
 */
export type FloatButtonToken = FullToken<'FloatButton'> & {
  /**
   * @desc FloatButton 尺寸
   * @descEN Size of FloatButton
   */
  floatButtonSize: number;
  /**
   * @desc FloatButton 图标尺寸
   * @descEN Icon size of FloatButton
   */
  floatButtonIconSize: number | string;

  // Position
  /**
   * @desc FloatButton 底部内边距
   * @descEN Bottom inset of FloatButton
   */
  floatButtonInsetBlockEnd: number;
  /**
   * @desc FloatButton 右侧内边距
   * @descEN Right inset of FloatButton
   */
  floatButtonInsetInlineEnd: number;
};

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/float-button/BackTop.tsx
  • vendor/components/float-button/FloatButton.tsx
  • vendor/components/float-button/FloatButtonGroup.tsx
  • vendor/components/float-button/PurePanel.tsx
  • vendor/components/float-button/context.ts
  • vendor/components/float-button/hooks/useScroll.ts
  • vendor/components/float-button/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.