# Close button

The icon-only button that closes a dialog, sheet, banner or panel, named "Close" in the current language.

- Family: action
- Import: `import { CloseButton } from "@senvenli/react/action";`
- Page: https://design.senvenli.com/docs/components/close-button
- JSON: https://design.senvenli.com/docs/components/close-button.json

## Example: Close

Named "Close" in the reader's language, with nothing to pass.

```tsx
import { CloseButton } from "@senvenli/react/action";

export default function Example() {
  return <CloseButton />;
}
```

## Examples

### A specific name

When several close buttons share a view, each says what it closes.

```tsx
import { CloseButton } from "@senvenli/react/action";
import { Card, CardHeader } from "@senvenli/react/display";

export default function Example() {
  return (
    <div className="max-w-sm">
      <Card variant="outline" density="compact">
        <CardHeader title="Filters" subtitle="Status: paid" actions={<CloseButton aria-label="Close filters" />} />
      </Card>
    </div>
  );
}
```

## Guidelines

### When to use it

- Closing a surface that can be dismissed.

### Use something else when

- [button](https://design.senvenli.com/docs/components/button.md): The action does more than dismiss, or needs a visible label.

## Accessibility

Built in:

- Named "Close" from the component strings.

You provide:

- A more specific `label` when several close buttons share a view.

## API reference

### CloseButton

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| radius | `ComponentRadius` |  | no | Corner radius: `none`, `small`, `medium` (the design), `large` or `full` (a pill). The provider's default otherwise. |
| tone | `ButtonTone` |  | no | `danger` for a destructive action (delete, discard); it keeps the variant's shape. |
| fullWidth | `boolean` |  | no | As wide as its container (a form's submit on a phone, a stacked set of actions). |
| size | `ButtonSize` | `"small"` | no |  |
| aria-label | `string` |  | no | Overrides the localized "Close" name. |

Behavior props from React Aria:

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| autoFocus | `boolean` |  | no | Whether the element should receive focus on render. |
| onFocus | `(e: FocusEvent<Element, Element>) => void` |  | no | Handler that is called when the element receives focus. |
| onBlur | `(e: FocusEvent<Element, Element>) => void` |  | no | Handler that is called when the element loses focus. |
| onClick | `(e: MouseEvent<FocusableElement, MouseEvent>) => void` |  | no | **Not recommended – use `onPress` instead.** `onClick` is an alias for `onPress` provided for compatibility with other libraries. `onPress` provides additional event details for non-mouse interactions. |
| isDisabled | `boolean` |  | no | Whether the button is disabled. |
| onPress | `(e: PressEvent) => void` |  | no | Handler that is called when the press is released over the target. |
| onPressStart | `(e: PressEvent) => void` |  | no | Handler that is called when a press interaction starts. |
| onPressEnd | `(e: PressEvent) => void` |  | no | Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. |
| onPressChange | `(isPressed: boolean) => void` |  | no | Handler that is called when the press state changes. |
| onPressUp | `(e: PressEvent) => void` |  | no | Handler that is called when a press is released over the target, regardless of whether it started on the target or not. |
| onFocusChange | `(isFocused: boolean) => void` |  | no | Handler that is called when the element's focus status changes. |
| type | `"button" \| "submit" \| "reset"` |  | no | The behavior of the button when used in an HTML form. |
| preventFocusOnPress | `boolean` |  | no | Whether to prevent focus from moving to the button when pressing it. Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, such as ComboBox's MenuTrigger or a NumberField's increment/decrement control. |
| form | `string` |  | no | The `<form>` element to associate the button with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#form). |
| formAction | `string \| ((formData: FormData) => void \| Promise<void>)` |  | no | The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner. |
| formEncType | `string` |  | no | Indicates how to encode the form data that is submitted. |
| formMethod | `string` |  | no | Indicates the HTTP method used to submit the form. |
| formNoValidate | `boolean` |  | no | Indicates that the form is not to be validated when it is submitted. |
| formTarget | `string` |  | no | Overrides the target attribute of the button's form owner. |
| name | `string` |  | no | Submitted as a pair with the button's value as part of the form data. |
| value | `string` |  | no | The value associated with the button's name when it's submitted with the form data. |
| excludeFromTabOrder | `boolean` |  | no | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. |
| isPending | `boolean` |  | no | Whether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers. |
| onHoverStart | `(e: HoverEvent) => void` |  | no | Handler that is called when a hover interaction starts. |
| onHoverEnd | `(e: HoverEvent) => void` |  | no | Handler that is called when a hover interaction ends. |
| onHoverChange | `(isHovering: boolean) => void` |  | no | Handler that is called when the hover state changes. |

Also takes 83 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-brand-bold`, `--ds-background-brand-bold-hovered`, `--ds-background-brand-bold-pressed`, `--ds-background-danger`, `--ds-background-danger-bold`, `--ds-background-danger-bold-hovered`, `--ds-background-disabled`, `--ds-background-neutral`, `--ds-background-neutral-hovered`, `--ds-background-neutral-pressed`, `--ds-background-neutral-subtle-hovered`, `--ds-background-selected`, `--ds-background-selected-hovered`, `--ds-background-selected-pressed`, `--ds-border`, `--ds-border-bold`, `--ds-border-focused`, `--ds-border-selected`, `--ds-easing-standard`, `--ds-link`, `--ds-link-pressed`, `--ds-radius-control-medium`, `--ds-radius-full`, `--ds-size-control`, `--ds-size-control-compact`, `--ds-size-control-large`, `--ds-size-icon`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-text`, `--ds-text-danger`, `--ds-text-disabled`, `--ds-text-on-brand`, `--ds-text-on-danger`, `--ds-text-subtle`

## Related

- [button](https://design.senvenli.com/docs/components/button.md)
