本文档介绍了 WordPress 组件库中的 Button 组件,用于通过点击或轻触让用户执行操作或做出选择。提供了详细的 Props 配置说明,包括样式、状态、可访问性等属性。
import { Button } from '@wordpress/components';
const Mybutton = () => (
<Button
variant="primary"
onClick={ handleClick }
>
Click here
</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>
);
__next40pxDefaultSizebooleanfalseStart opting into the larger default height that will become the
default size in a future version.
accessibleWhenDisabledbooleanfalseWhether 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.
childrenReactNodeThe button’s children.
descriptionstringA visually hidden accessible description for the button.
disabledbooleanWhether 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.
hrefstringIf provided, renders a instead of button.
iconIconType | nullIf provided, renders an Icon component inside the button.
iconPosition"left" | "right"'left'If provided with icon, sets the position of icon relative to the text.
iconSizenumberIf provided with icon, sets the icon size.
Please refer to the Icon component for more details regarding
the default value of its size prop.
isBusybooleanIndicates activity while a action is being performed.
isDestructivebooleanRenders a red text-based button style to indicate destructive behavior.
isPressedbooleanRenders a pressed button style.
labelstringSets the aria-label of the component, if none is provided.
Sets the Tooltip content if showTooltip is provided.
shortcutstring | { display: string; ariaLabel: string; }If provided with showTooltip, appends the Shortcut label to the tooltip content.
If an object is provided, it should contain display and ariaLabel keys.
showTooltipbooleanIf provided, renders a Tooltip component for the button.
size"small" | "default" | "compact"'default'The size of the button.
'default': For normal text-label buttons, unless it is a toggle button.'compact': For toggle buttons, icon buttons, and buttons when used in context of either.'small': For icon buttons associated with more advanced or auxiliary features.If the deprecated isSmall prop is also defined, this prop will take precedence.
textstringIf provided, displays the given text inside the button. If the button contains children elements, the text is displayed before them.
tooltipPosition"top" | "middle" | "bottom" | "top center" | "top left" | "top right" | "middle center" | "middle left" | "middle right" | "bottom center" | ...If provided with showTooltip, sets the position of the tooltip.
Please refer to the Tooltip component for more details regarding the defaults.
targetstringIf provided with href, sets the target attribute to the a.
variant"link" | "primary" | "secondary" | "tertiary"Specifies the button’s style.
The accepted values are:
'primary' (the primary button styles)'secondary' (the default button styles)'tertiary' (the text-based button styles)'link' (the link button styles)