Button


目录

See the WordPress Storybook for more detailed, interactive documentation.

Lets users take actions and make choices with a single click or tap.

import { Button } from '@wordpress/components';
const Mybutton = () => (
  <Button
    variant="primary"
    onClick={ handleClick }
  >
    Click here
  </Button>
);

Props

__next40pxDefaultSize

Start opting into the larger default height that will become the
default size in a future version.

accessibleWhenDisabled

Whether to keep the button focusable when disabled.

In most cases, it is recommended to set this to true. Disabling a control without maintaining focusability
can cause accessibility issues, by hiding their presence from screen reader users,
or by preventing focus from returning to a trigger element.

Learn more about the focusability of disabled controls
in the WAI-ARIA Authoring Practices Guide.

children

The button’s children.

description

A visually hidden accessible description for the button.

disabled

Whether the button is disabled. If true, this will force a button element
to be rendered, even when an href is given.

In most cases, it is recommended to also set the accessibleWhenDisabled prop to true.

href

If provided, renders a instead of button.

icon

If provided, renders an Icon component inside the button.

iconPosition

If provided with icon, sets the position of icon relative to the text.

iconSize

If provided with icon, sets the icon size.
Please refer to the Icon component for more details regarding
the default value of its size prop.

isBusy

Indicates activity while a action is being performed.

isDestructive

Renders a red text-based button style to indicate destructive behavior.

isPressed

Renders a pressed button style.

label

Sets the aria-label of the component, if none is provided.
Sets the Tooltip content if showTooltip is provided.

shortcut

If provided with showTooltip, appends the Shortcut label to the tooltip content.
If an object is provided, it should contain display and ariaLabel keys.

showTooltip

If provided, renders a Tooltip component for the button.

size

The size of the button.

If the deprecated isSmall prop is also defined, this prop will take precedence.

text

If provided, displays the given text inside the button. If the button contains children elements, the text is displayed before them.

tooltipPosition

If provided with showTooltip, sets the position of the tooltip.
Please refer to the Tooltip component for more details regarding the defaults.

target

If provided with href, sets the target attribute to the a.

variant

Specifies the button’s style.

The accepted values are:

  1. 'primary' (the primary button styles)
  2. 'secondary' (the default button styles)
  3. 'tertiary' (the text-based button styles)
  4. 'link' (the link button styles)

版本号 #2
由 壳壳虫 创建于 2026-10-31 18:12:22 UTC
由 壳壳虫 更新于 2026-10-31 18:12:24 UTC