# media-fullscreen-button

Accessible fullscreen toggle button with keyboard support and state reflection

## Import

```ts
import '@videojs/html/ui/fullscreen-button';
```

## Anatomy

```html
<media-fullscreen-button></media-fullscreen-button>
```

## Behavior

Toggles fullscreen mode. The button derives two state hooks from `availability`:

- **`disabled`** (`true` until fullscreen is available, or when the `disabled` prop is set) — sets `aria-disabled="true"` and `data-disabled`. A prop-disabled, available button stays focusable but does not activate.
- **`hidden`** (`true` while fullscreen is `"unavailable"` or `"unsupported"`) — applies the native HTML `hidden` attribute on the custom element.

## Styling

You can style the button based on fullscreen state:

```css
/* In fullscreen */
media-fullscreen-button[data-fullscreen] {
  background: red;
}

/* Non-interactive (disabled prop) */
media-fullscreen-button[data-disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
```

The button remains hidden until fullscreen is available.

The element receives the native `hidden` attribute. No extra CSS is required.

## Accessibility

Renders a `<button>` with an automatic `aria-label`: “Enter fullscreen” or “Exit fullscreen”. Override with the `label` prop. Keyboard activation: Enter / Space.

## Examples

### Basic Usage

**index.html**

```html
<video-player class="video-player">
  <media-container>
    <video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" autoplay muted playsinline loop></video>
    <media-fullscreen-button class="media-fullscreen-button">
      <span class="fullscreen">Exit Fullscreen</span>
      <span class="not-fullscreen">Fullscreen</span>
    </media-fullscreen-button>
  </media-container>
</video-player>
```

**index.css**

```css
.video-player media-container {
  position: relative;
  display: block;
}

.video-player media-container video {
  width: 100%;
}

.media-fullscreen-button {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding-block: 8px;
  padding-inline: 20px;
  color: black;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 9999px;
  backdrop-filter: blur(10px);
}

.media-fullscreen-button .fullscreen {
  display: none;
}
.media-fullscreen-button .not-fullscreen {
  display: none;
}
.media-fullscreen-button[data-fullscreen] .fullscreen {
  display: inline;
}
.media-fullscreen-button:not([data-fullscreen]) .not-fullscreen {
  display: inline;
}
```

**index.ts**

```ts
import '@videojs/html/video/player';
import '@videojs/html/ui/container';
import '@videojs/html/ui/fullscreen-button';
```

## API Reference

### Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `disabled` | `boolean` | `false` | Whether the button is disabled. |
| `label` | `{ key: string; text: string } \| string \| ((state: FullscreenButtonState) => Text \| string)` | `''` | Custom label for the button. |

### State

State is reflected as data attributes for CSS styling.

| Property | Type | Description |
| --- | --- | --- |
| `fullscreen` | `boolean` | Whether fullscreen mode is currently active. |
| `label` | `{ key: string; text: string } \| string` | |
| `availability` | `MediaFeatureAvailability` | Whether fullscreen can be requested on this platform. |
| `disabled` | `boolean` | Non-interactive but still focusable (mirrors `aria-disabled`). |
| `hidden` | `boolean` | Whether the button is hidden until fullscreen is available. |

### Data attributes

| Attribute | Type | Description |
| --- | --- | --- |
| `data-fullscreen` | — | Present when fullscreen mode is active. |
| `data-availability` | `MediaFeatureAvailability` | Indicates fullscreen availability (`available`, `unavailable`, `unsupported`). |
| `data-disabled` | — | Present when the button is non-interactive (mirrors `aria-disabled`). |
| `data-hidden` | — | Present when the button is hidden because fullscreen is not available. |