-
Notifications
You must be signed in to change notification settings - Fork 61
refactor(packages): improve webkit presentation API handling and button availability #1362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
16e196f
refactor(packages): improve webkit presentation API handling and butt…
mihar-22 375cf99
fix(packages): resolve typecheck failures in button tests and cast fe…
mihar-22 09cd58a
feat(packages): add `available` state and `data-available` attr to ca…
mihar-22 dfa78df
docs(core): add JSDoc to cast button data attrs
mihar-22 7274036
docs(core): add JSDoc to CastButtonState interface
mihar-22 b926c35
fix(core): correct pip feature event target and fullscreen-to-pip tra…
mihar-22 d8824ec
docs(design): document disabled and hidden states for controls
mihar-22 9abe153
refactor(packages)!: replace `available` state with `disabled` and `h…
mihar-22 393edb8
fix(core): sync pip state on play event
mihar-22 30c4dd0
fix(skin): replace old availability Tailwind classes with data-disabled
mihar-22 15c3a32
docs(site): add data-disabled styling examples to pip and fullscreen …
mihar-22 6ee1288
fix(test): skip pip button assertion when hidden on WebKit
mihar-22 516fbba
refactor(packages): propagate media button errors to caller instead o…
mihar-22 b4cdc2d
fix(core): guard webkit pip exit and fix api check order
mihar-22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| --- | ||
| status: decided | ||
| date: 2026-04-18 | ||
| --- | ||
|
|
||
| # Disabled & Hidden States for Controls | ||
|
|
||
| ## Decision | ||
|
|
||
| Use `aria-disabled` (never HTML `disabled`) for all toolbar buttons. Three visual states driven by data attributes: | ||
|
|
||
| | State | ARIA | HTML (custom element) | React | Styling | | ||
| |-------|------|-----------------------|-------|---------| | ||
| | **Unsupported** | `aria-disabled="true"` | `hidden` + `data-hidden` + `data-disabled` | returns `null` | Browser hides natively | | ||
| | **Unavailable** (Cast only) | `aria-disabled="true"` | `data-disabled` | `data-disabled` on `<button>` | Reduced opacity via `[data-disabled]` | | ||
| | **Disabled** (prop) | `aria-disabled="true"` | `data-disabled` | `data-disabled` on `<button>` | Reduced opacity via `[data-disabled]` | | ||
| | **Available + enabled** | _(none)_ | _(none)_ | _(none)_ | Fully interactive | | ||
|
|
||
| `data-availability` remains as a string enum (`available`, `unavailable`, `unsupported`) for consumers that need the raw value. | ||
|
|
||
| ## Context | ||
|
|
||
| Feature buttons (Fullscreen, PiP, Cast) need to communicate three distinct states to users and assistive technology: | ||
|
|
||
| 1. **Unsupported** — the browser lacks the capability entirely (e.g., PiP on older Safari). Applies to Fullscreen, PiP, and Cast. | ||
| 2. **Unavailable** — the API exists but no target is available (e.g., no cast device found). Only applies to Cast. | ||
| 3. **Disabled** — the developer explicitly disabled the control via a prop | ||
|
|
||
| Unsupported features are hidden entirely. Unavailable features (Cast only — no device found) and explicitly disabled buttons remain visible but non-interactive. `disabled` in state covers both the prop and feature unavailability. We evaluated `disabled` vs `aria-disabled`, `hidden` vs `aria-hidden`, and how Radix, Base UI, and WAI-ARIA APG handle these patterns. | ||
|
|
||
| ## Alternatives Considered | ||
|
|
||
| - **HTML `disabled` attribute** — Removes elements from the tab order entirely. This breaks the APG toolbar pattern, which requires all toolbar buttons to remain focusable via arrow keys. It also prevents tooltips and hover states from working on disabled buttons. | ||
|
|
||
| - **Hybrid approach (like Base UI's `focusableWhenDisabled`)** — Adds a prop to toggle between `disabled` and `aria-disabled`. Unnecessary complexity for our use case since we always want buttons to remain focusable. | ||
|
|
||
| - **CSS-only hiding (`display: none` via data attributes)** — Our prior approach used `[data-availability]:not([data-available])` to hide buttons. This works but lacks native semantics. The HTML `hidden` attribute provides the same effect with proper semantics and works without any CSS. | ||
|
|
||
| ## Rationale | ||
|
|
||
| ### Why `aria-disabled` over `disabled` | ||
|
|
||
| The WAI-ARIA APG toolbar pattern explicitly recommends `aria-disabled` for toolbar buttons: | ||
|
|
||
| - **Keeps buttons in tab order** — keyboard users can discover disabled controls and understand what's available | ||
| - **Allows tooltips** — hover events still fire on `aria-disabled` elements, so tooltips can explain why a control is disabled | ||
| - **Consistent across custom elements** — HTML `disabled` only has native behavior on form controls (`<button>`, `<input>`), not custom elements | ||
|
|
||
| This aligns with both Radix (uses `aria-disabled` for custom interactive elements, `[data-disabled]` for styling) and Base UI (uses `aria-disabled` when `focusableWhenDisabled` is true, exposes `[data-disabled]`). | ||
|
|
||
| ### Why HTML `hidden` for unavailable features | ||
|
|
||
| When a feature is unsupported or unavailable, the button should not be visible at all. The HTML `hidden` attribute: | ||
|
|
||
| - Works without CSS — no `display: none` rule needed | ||
| - Has native browser semantics | ||
| - Is set via `getAttrs()` alongside `aria-disabled`, keeping all attribute logic in one place | ||
|
|
||
| On the React side, the component returns `null` instead — the idiomatic React approach for conditional rendering. | ||
|
|
||
| ### Why separate `data-disabled` and `data-hidden` | ||
|
|
||
| These serve different styling purposes: | ||
|
|
||
| - `data-disabled` — reduced opacity, `cursor: not-allowed` (button is visible but non-interactive) | ||
| - `data-hidden` — a styling hook for consumers; the HTML `hidden` attribute handles actual hiding | ||
|
|
||
| Both are driven by state fields (`disabled`, `hidden`) through the standard `applyStateDataAttrs` data attribute system. | ||
|
|
||
| ## References | ||
|
|
||
| - [WAI-ARIA APG Toolbar Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/toolbar/) — recommends `aria-disabled` for toolbar buttons | ||
| - [WAI-ARIA APG Button Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/) — "when the action associated with a button is unavailable, the button has `aria-disabled` set to `true`" | ||
| - [Radix Primitives Accessibility](https://www.radix-ui.com/primitives/docs/overview/accessibility) — `aria-disabled` + `[data-disabled]` for custom elements | ||
| - [Base UI Accessibility](https://base-ui.com/react/handbook/styling) — `focusableWhenDisabled` prop, `[data-disabled]` attr | ||
| - [MDN: aria-disabled](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-disabled) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { isFunction, isObject } from '@videojs/utils/predicate'; | ||
|
|
||
| import type { | ||
| MediaBufferCapability, | ||
| MediaErrorCapability, | ||
| MediaFullscreenCapability, | ||
| MediaPauseCapability, | ||
| MediaPictureInPictureCapability, | ||
| MediaPlaybackRateCapability, | ||
| MediaRemotePlaybackCapability, | ||
| MediaSeekCapability, | ||
| MediaSourceCapability, | ||
| MediaTextTrackCapability, | ||
| MediaVolumeCapability, | ||
| } from './types'; | ||
|
|
||
| export function isMediaPauseCapable(value: unknown): value is MediaPauseCapability { | ||
| return isObject(value) && 'paused' in value && 'ended' in value && 'pause' in value && isFunction(value.pause); | ||
| } | ||
|
|
||
| export function isMediaSeekCapable(value: unknown): value is MediaSeekCapability { | ||
| return isObject(value) && 'currentTime' in value && 'duration' in value && 'seeking' in value; | ||
| } | ||
|
|
||
| export function isMediaSourceCapable(value: unknown): value is MediaSourceCapability { | ||
| return ( | ||
| isObject(value) && | ||
| 'src' in value && | ||
| 'currentSrc' in value && | ||
| 'readyState' in value && | ||
| 'load' in value && | ||
| isFunction(value.load) | ||
| ); | ||
| } | ||
|
|
||
| export function isMediaVolumeCapable(value: unknown): value is MediaVolumeCapability { | ||
| return isObject(value) && 'volume' in value && 'muted' in value; | ||
| } | ||
|
|
||
| export function isMediaPlaybackRateCapable(value: unknown): value is MediaPlaybackRateCapability { | ||
| return isObject(value) && 'playbackRate' in value; | ||
| } | ||
|
|
||
| export function isMediaBufferCapable(value: unknown): value is MediaBufferCapability { | ||
| return isObject(value) && 'buffered' in value && 'seekable' in value; | ||
| } | ||
|
|
||
| export function isMediaErrorCapable(value: unknown): value is MediaErrorCapability { | ||
| return isObject(value) && 'error' in value; | ||
| } | ||
|
|
||
| export function isMediaTextTrackCapable(value: unknown): value is MediaTextTrackCapability { | ||
| return isObject(value) && 'textTracks' in value; | ||
| } | ||
|
|
||
| export function isMediaRemotePlaybackCapable(value: unknown): value is MediaRemotePlaybackCapability { | ||
| return isObject(value) && 'remote' in value && isObject(value.remote); | ||
| } | ||
|
|
||
| export function isMediaFullscreenCapable(value: unknown): value is MediaFullscreenCapability { | ||
| return isObject(value) && 'requestFullscreen' in value && isFunction(value.requestFullscreen); | ||
| } | ||
|
|
||
| export function isMediaPictureInPictureCapable(value: unknown): value is MediaPictureInPictureCapability { | ||
| return isObject(value) && 'requestPictureInPicture' in value && isFunction(value.requestPictureInPicture); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.