--- localeCode: en-US order: 19 category: Input title: Button subTitle: Button icon: doc-button dir: column brief: Users use buttons to trigger an operation or jump. --- ## Demos ### How to import ```jsx import import { Button, SplitButtonGroup } from '@douyinfe/semi-ui'; ``` ### Button Type Buttons support the following types: - Primary button ("primary", default) - Secondary button ("secondary") - Tertiary button ("tertiary") - Warning button ("warning") - Danger button ("danger") ```jsx live=true dir="column" import React from 'react'; import { Button } from '@douyinfe/semi-ui'; function ButtonDemo() { return (
); } ``` #### About the Font Color [CSS Variables](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Using_CSS_custom_properties) are used with the button: - `var(--semi-color-primary)`: main - `var(--semi-color-secondary)`: secondary - `var(--semi-color-colored)`: third - `var(--semi-color-warning)`: warning - `var(--semi-color-danger)`: danger You can define your elements directly using these theme colors. ```jsx live=true dir="column" import React from 'react'; function ButtonDemo() { const types = [['primary', 'primary'], ['secondary', 'secondary'], ['tertiary', 'tertiary'], ['warning', 'warning'], ['danger', 'danger']]; return (
{types.map((type, index) => ( {Array.isArray(type) ? type[1]: type} ))}
); } ``` ### Button Theme The themes currently available are: - `light`: light background - `solid`: dark background - `borderless`: no background The default theme is `light` #### Light Background ```jsx live=true dir="column" import React from 'react'; import { Button } from '@douyinfe/semi-ui'; function ButtonDemo() { const themes = [['light', 'light']]; const types = [['primary', 'primary'], ['secondary', 'secondary'], ['tertiary', 'tertiary'], ['warning', 'warning'], ['danger', 'danger']]; return (
{ themes.map((theme, idxTheme) => (
)) }
); } ``` #### Dark Background ```jsx live=true dir="column" import React from 'react'; import { Button } from '@douyinfe/semi-ui'; function ButtonDemo() { const themes = [['solid', 'solid']]; const types = [['primary', 'primary'], ['secondary', 'secondary'], ['tertiary', 'tertiary'], ['warning', 'warning'], ['danger', 'danger']]; return (
{ themes.map((theme, idxTheme) => (
)) }
); } ``` #### No Background ```jsx live=true dir="column" import React from 'react'; import { Button } from '@douyinfe/semi-ui'; function ButtonDemo() { const themes = [['borderless', 'borderless']]; const types = [['primary', 'primary'], ['secondary', 'secondary'], ['tertiary', 'tertiary'], ['warning', 'warning'], ['danger', 'danger']]; return (
{ themes.map((theme, idxTheme) => (
)) }
); } ``` ### Size Three sizes are defined by default: - Big: "Large" - Default: "default." - Small: "Small" ```jsx live=true dir="column" import React from 'react'; import { Button } from '@douyinfe/semi-ui'; function ButtonDemo() { return (
); } ``` ### Block Button The block button has a predefined width, and its width is independent of the width of the contents of the button. ```jsx live=true dir="column" import React from 'react'; import { Button } from '@douyinfe/semi-ui'; function ButtonDemo() { return (
); } ``` ### Icon Button An icon that defines a button. ```jsx live=true dir="column" import React from 'react'; import { Button } from '@douyinfe/semi-ui'; import { IconCamera, IconSidebar, IconChevronDown } from '@douyinfe/semi-icons'; function ButtonDemo() { return (
Default Status:

); } ``` ### Link Button We recommend using Typography to achieve link text button. Refer to [Typography](/en-US/basic/typography) for more information. ```jsx live=true import React from 'react'; import { Typography } from '@douyinfe/semi-ui'; import { IconLink } from '@douyinfe/semi-icons'; function Demo() { const { Text } = Typography; return (
Link

Open Website

} underline>Link
); } ``` ### Prohibited Status ```jsx live=true dir="column" import React from 'react'; import { Button } from '@douyinfe/semi-ui'; function ButtonDemo() { return (
); } ``` ### Loading State The button supports the Loading state, by setting the loading parameter value to true, note: the state priority is higher than the loading state. ```jsx live=true dir="column" import React, { useState } from 'react'; import { Button } from '@douyinfe/semi-ui'; import { IconDelete } from '@douyinfe/semi-icons'; function ButtonDemo() { const [saveLoading, setSaveLoading] = useState(false); const [delLoading, setDelLoading] = useState(true); const [repLoading, setRepLoading] = useState(true); const reset = status => { status = !!status; setSaveLoading(status); setDelLoading(status); setRepLoading(status); }; return (

); } ``` ### Button Combination You can put multiple buttons in `ButtonGroup` In the container, by setting `size`, `disabled`, `type` You can uniformly set the button size in the button combination, whether disabled and type. #### Combined Dimensions ```jsx live=true dir="column" import React from 'react'; import { Button, ButtonGroup } from '@douyinfe/semi-ui'; function ButtonDemo() { const sizes = ['large', 'default', 'small']; return (
{sizes.map(size => (
))}
); } ``` #### Combined Disabled ```jsx live=true dir="column" import React from 'react'; import { Button, ButtonGroup } from '@douyinfe/semi-ui'; function ButtonDemo() { return (
); } ``` #### Combined Type ```jsx live=true dir="column" import React from 'react'; import { Button, ButtonGroup } from '@douyinfe/semi-ui'; function ButtonDemo() { const types = ['primary', 'secondary', 'tertiary', 'warning', 'danger']; return (
{types.map(type => (
))}
); } ``` ### Split Button Group **V1.12.0** In the scene where `Button` and `Dropdown` are combined, split buttons can be used. The split buttons add the space between the buttons and change the rounded corners of the buttons. #### Basic Usage ```jsx live=true dir="column" import React, { useState } from 'react'; import { SplitButtonGroup, Dropdown, Button } from '@douyinfe/semi-ui'; import { IconTreeTriangleDown } from '@douyinfe/semi-icons'; function SplitButtonDemo(){ const menu = [ { node: 'title', name: 'Title' }, { node: 'item', name: 'Edit', onClick: () => console.log('Edit clicked') }, { node: 'item', name: 'Reset', type: 'secondary' }, { node: 'divider' }, { node: 'item', name: 'Create', type: 'tertiary' }, { node: 'item', name: 'Copy', type: 'warning' }, { node: 'divider' }, { node: 'item', name: 'Delete', type: 'danger' }, ]; const [btnVisible,setBtnVisible] = useState({ 1:false, 2:false, 3:false }); const handleVisibleChange = (key,visible)=>{ newBtnVisible = {...btnVisible}; newBtnVisible[key] = visible; setBtnVisible(newBtnVisible); }; return (
handleVisibleChange(1,v)} menu={menu} trigger="click" position="bottomRight"> handleVisibleChange(2,v)} menu={menu} trigger="click" position="bottomRight"> handleVisibleChange(3,v)} menu={menu} trigger="click" position="bottomRight">
); } ``` ## API Reference ### Button | Properties | Instructions | Type | Default | | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | --------- | | aria-label | Label of the button | string | - | | block | Set the button to the block level button | boolean | false | | className | Class name | string | | | disabled | Prohibited status | boolean | false | | htmlType | Set the `button` native `type` value, optional values: `"button"`, `"reset"`, `"submit"` | string | "button" | | icon | Icon | ReactNode | | | iconPosition | Icon location, optional value: `"left"`\|`"right"` | string | `"left"` | | loading | Loading state | boolean | false | | noHorizontalPadding | Set whether to remove the inner margin in the horizontal direction, only valid for iconButton, optional: `true` (equivalent to \["left", "right"\]), "left", "right", \["left", "right"\] | boolean\|string\| Array | false | | size | Button size, optional value: `"large"`,`"default"`,`"small"` | string | "default" | | style | Custom style | CSSProperties | | | theme | Button theme, optional value: `"solid"` (with background color), `"borderless"` (no background color), `"light"` (light background color) | string | "light" | | type | Type, optional values: `"primary"`,`"secondary"`, `"late"`, `"warning"`, `"danger"` | string | "primary" | | onClick | Click event | Function(MouseEvent) | | | onMouseDown | Mouse down | Function(MouseEvent) | | | onMouseEnter | Mouse Enter | Function(MouseEvent) | | | onMouseLeave | Mouse Leave | Function(MouseEvent) | | ### ButtonGroup | Properties | Instructions | Type | Default | | ---------- | --------------------------------------------------------------------------------------- | ------- | --------- | | aria-label | Label of the button group | string | - | | disabled | Disabled status | boolean | false | | size | Button size, optional value: `"large"`,`"default"`,`"small"` | string | "default" | | type | Type, optional values: `"primary"`,`"secondary"`, `"tertiary"`, `"warning"`, `"danger"` | string | "primary" | | className | Custom class name | string | | ### SplitButtonGroup **V1.12.0** | Properties | Instructions | Type | Default | | ----------- | -------------------------------------------------------------- | -------- | --------- | | aria-label | Label of the button group | string | - | | style | Custom style | CSSProperties | | | className | Custom class name | string | | ## Accessibility ### ARIA - `aria-label` is used to indicate the function of the button. For icon buttons, we recommend using this attribute - `aria-disabled` is synchronized with the disabled attribute, indicating that the button is disabled ### Keyboard and Focus - `Button`'s focus management is consistent with native `button`, keyboard users can use `Tab` and `Shift + Tab` to switch focus - The trigger of `Button` is the same as the native `button`, when the `button` is focused, it can be activated by `Enter` or `Space` key - The buttons in the `ButtonGroup` are managed in the same way as the focus of a single `button`, and can be switched by `Tab` and `Shift + Tab` ## Content Guidelines - Buttons need to be clear and predictable, users should be able to predict what will happen when they click the button - Buttons should always start with a strong verb that encourages action - To give the user enough context, use {verb}+{noun} content formulas on buttons; in addition to common actions like "Done", "Close", "Cancel" or "OK" | ✅ Recommended usage | ❌ Deprecated usage | | --- | --- | |
} darkModeImage={} description={'No permission to view this page'}/>
|
} darkModeImage={} description={'No permission to view this page'}/>
| - When the button is combined with other components, the button can only display {verb}, such as "Add", "Create", if the other components (such as Modal and Sidesheet) already provide enough context for the information | ✅ Recommended usage | ❌ Deprecated usage | | --- | --- | | | | - Always write in Sentence case | ✅ Recommended usage | ❌ Deprecated usage | | --- | --- | | Create project | Create
Create a project| | Edit profile | Edit | ## Design Tokens