PiPButton
Accessible picture-in-picture toggle button with keyboard support and state reflection
Anatomy
<PiPButton />Behavior
Toggles picture-in-picture (PiP) mode. Detects platform support through availability — when PiP is "unsupported", the toggle does nothing.
Styling
You can style the button based on PiP state:
React renders a <button> element. Add a className to style it:
/* In PiP mode */
.pip-button[data-pip] {
background: red;
}Consider hiding the button when unsupported:
.pip-button[data-availability="unsupported"] {
display: none;
}Accessibility
Renders a <button> with an automatic aria-label: “Enter PiP” or “Exit PiP”. Override with the label prop. Keyboard activation: Enter / Space.
Examples
Basic Usage
import { createPlayer, PiPButton } from '@videojs/react';
import { Video, videoFeatures } from '@videojs/react/video';
import './BasicUsage.css';
const Player = createPlayer({ features: videoFeatures });
export default function BasicUsage() {
return (
<Player.Provider>
<Player.Container className="react-pip-button-basic">
<Video
src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4"
autoPlay
muted
playsInline
loop
/>
<PiPButton
className="react-pip-button-basic__button"
render={(props, state) => <button {...props}>{state.pip ? 'Exit PiP' : 'Enter PiP'}</button>}
/>
</Player.Container>
</Player.Provider>
);
}
.react-pip-button-basic {
position: relative;
}
.react-pip-button-basic video {
width: 100%;
}
.react-pip-button-basic__button {
padding-block: 8px;
position: absolute;
bottom: 10px;
right: 10px;
background: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
color: black;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 9999px;
padding-inline: 20px;
cursor: pointer;
}
API Reference
Props
| Prop | Type | Default | Details |
|---|---|---|---|
disabled | boolean | false | |
| |||
label | string | function | '' | |
| |||
State
State is accessible via the render, className, and style props.
| Property | Type | Details |
|---|---|---|
availability | 'available' | 'unavailable' | 'unsupp... | |
| ||
pip | boolean | |
| ||
label | string | |
Data attributes
| Attribute | Type | Details |
|---|---|---|
data-pip | ||
| ||
data-availability | 'available' | 'unavailable' | 'unsupp... | |
| ||