--- title: Button description: "`Button`は、フォームの送信、モーダルの開閉など、ユーザーが操作できるインタラクティブなコンポーネントです。" links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/button/button.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/button - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-button--basic --- ```tsx ``` ## 使い方 ```tsx import { Button, ButtonGroup } from "@yamada-ui/react" ``` ```tsx import { Button, ButtonGroup } from "@/components/ui" ``` ```tsx import { Button, ButtonGroup } from "@workspaces/ui" ``` ```tsx )} ``` ### サイズを変更する ```tsx {(size, index) => ( )} ``` ### カラースキームを変更する ```tsx {(colorScheme, index) => ( )} ``` ### 形を変える 角丸にする場合は、`fullRounded`を`true`にします。 ```tsx {(variant, index) => ( )} ``` ### 無効にする 無効にする場合は、`disabled`を`true`にします。 ```tsx {(variant, index) => ( )} ``` ### アイコンを追加する アイコンを追加する場合は、`startIcon`または`endIcon`に`ReactNode`を設定します。 ```tsx ``` ### ローディングアニメーションを使う ローディングアニメーションを使う場合は、`loading`を`true`にします。また、ローディング中にテキストを変更する場合は、`loadingMessage`を使用します。 ```tsx ``` :::note `Button`のローディングは、内部で[Loading](https://yamada-ui.com/docs/components/loading.md)を使用しています。 ::: ### グループ化する ```tsx Button } /> Button Button Button Button Button Button Button Button Button Button Button Button ``` ## Props ### Button | Prop | Default | Type | Description | | ------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"solid"` | `"ghost" \| "outline" \| "solid" \| "subtle" \| "surface" ...` | The variant of the component. | | `active` | `false` | `boolean` | If `true`, the button is represented as active. | | `disabled` | `false` | `boolean` | If `true`, the button is disabled. | | `disableRipple` | `false` | `boolean` | If `true`, disable ripple effects when pressing a element. | | `endIcon` | - | `ReactNode` | The icon to display at the end side of the button. | | `fullRounded` | `false` | `boolean` | If `true`, the button is full rounded. Else, it'll be slightly round. | | `iconProps` | - | `ButtonIconProps` | The props of the icon element. | | `loading` | `false` | `boolean` | If `true`, the loading state of the button is represented. | | `loadingIcon` | `"oval"` | `Loading.Scheme \| ReactNode` | The icon to display when the button is loading. | | `loadingMessage` | - | `ReactNode` | The message to display when the button is loading. | | `loadingPlacement` | `"start"` | `"end" \| "start"` | The placement of the loading indicator. Accepts `start` or `end`. | | `loadingProps` | - | `ButtonLoadingProps` | The props of the loading icon element. | | `startIcon` | - | `ReactNode` | The icon to display at the start side of the button. | | `type` | `"button"` | `HTMLProps<"button">["type"]` | The type of button. Accepts `button`, `reset`, or `submit`. | ### ButtonGroup.Root | Prop | Default | Type | Description | | ------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"solid"` | `"ghost" \| "outline" \| "solid" \| "subtle" \| "surface" ...` | The variant of the component. | | `align` | - | `"-moz-initial" \| "baseline" \| "center" \| "end" \| "flex-end" \| "flex-start" \| "inherit" \| "initial" \| "normal" \| "revert-layer" ...` | The CSS `align-items` property. | | `attached` | `false` | `boolean` | If `true`, the borderRadius of button that are direct children will be altered to look flushed together. | | `basis` | - | `"-moz-fit-content" \| "-moz-initial" \| "-moz-max-content" \| "-moz-min-content" \| "-webkit-auto" \| "0.5" \| "1.5" \| "1" \| "1/12" \| "1/2" ...` | The CSS `flex-basis` property. | | `direction` | - | `"-moz-initial" \| "column-reverse" \| "column" \| "inherit" \| "initial" \| "revert-layer" \| "revert" \| "row-reverse" \| "row" \| "unset" ...` | The CSS `flex-direction` property. | | `disabled` | `false` | `boolean` | If `true`, all wrapped button will be disabled. | | `fullRounded` | `false` | `boolean` | If `true`, the button is full rounded. Else, it'll be slightly round. | | `grow` | `false` | `boolean` | If `true`, the children will grow to fill the available space. | | `justify` | - | `"-moz-initial" \| "center" \| "end" \| "flex-end" \| "flex-start" \| "inherit" \| "initial" \| "left" \| "normal" \| "revert-layer" ...` | The CSS `justify-content` property. | | `orientation` | `"horizontal"` | `"horizontal" \| "vertical"` | The orientation of the group. | | `shrink` | - | `"-moz-initial" \| "inherit" \| "initial" \| "revert-layer" \| "revert" \| "unset" \| number & {} ...` | The CSS `flex-shrink` property. | | `stacking` | - | `"first-on-top" \| "last-on-top"` | The stacking order of the group. | | `wrap` | - | `"-moz-initial" \| "inherit" \| "initial" \| "nowrap" \| "revert-layer" \| "revert" \| "unset" \| "wrap-reverse" \| "wrap" ...` | The CSS `flex-wrap` property. | ### ButtonGroup.Item | Prop | Default | Type | Description | | ------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"solid"` | `"ghost" \| "outline" \| "solid" \| "subtle" \| "surface" ...` | The variant of the component. | | `active` | `false` | `boolean` | If `true`, the button is represented as active. | | `disabled` | `false` | `boolean` | If `true`, the button is disabled. | | `disableRipple` | `false` | `boolean` | If `true`, disable ripple effects when pressing a element. | | `endIcon` | - | `ReactNode` | The icon to display at the end side of the button. | | `fullRounded` | `false` | `boolean` | If `true`, the button is full rounded. Else, it'll be slightly round. | | `iconProps` | - | `ButtonIconProps` | The props of the icon element. | | `loading` | `false` | `boolean` | If `true`, the loading state of the button is represented. | | `loadingIcon` | `"oval"` | `Loading.Scheme \| ReactNode` | The icon to display when the button is loading. | | `loadingMessage` | - | `ReactNode` | The message to display when the button is loading. | | `loadingPlacement` | `"start"` | `"end" \| "start"` | The placement of the loading indicator. Accepts `start` or `end`. | | `loadingProps` | - | `ButtonLoadingProps` | The props of the loading icon element. | | `startIcon` | - | `ReactNode` | The icon to display at the start side of the button. | | `type` | `"button"` | `HTMLProps<"button">["type"]` | The type of button. Accepts `button`, `reset`, or `submit`. | ## アクセシビリティ `Button`は、アクセシビリティに関して[WAI-ARIA - Button Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/)に従います。 ### キーボード操作 | キー | 説明 | 状態 | | ---------------- | ---------------------------------------------- | ---- | | `Space`, `Enter` | フォーカスしているボタンをアクティブにします。 | - | ### ARIAロールと属性 | コンポーネント | ロールと属性 | 使い方 | | -------------- | --------------- | ---------------------------- | | `Button` | `role="button"` | ボタンであることを示します。 |