Skip to content

Commit 76f01d3

Browse files
authored
fix: Audio block iOS file picker compatibility (#137)
iOS Safari's `accept` attribute lacks wildcard `audio/*` support. This patch can be removed once [the issue](WordPress/gutenberg#70119) is addressed in a future release. See: https://stackoverflow.com/a/66859581
1 parent ccf6c9e commit 76f01d3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/node_modules/@wordpress/components/build-module/form-file-upload/index.js b/node_modules/@wordpress/components/build-module/form-file-upload/index.js
2+
index 9f1440e..e256971 100644
3+
--- a/node_modules/@wordpress/components/build-module/form-file-upload/index.js
4+
+++ b/node_modules/@wordpress/components/build-module/form-file-upload/index.js
5+
@@ -55,12 +55,23 @@ export function FormFileUpload({
6+
...props,
7+
children: children
8+
});
9+
+ const isSafari = typeof window !== "undefined" &&
10+
+ !!window.document?.createElement &&
11+
+ /mac|iphone|ipad|ipod/i.test( window?.navigator?.platform ) &&
12+
+ /apple/i.test(window?.navigator?.vendor);
13+
+ let compatAccept = accept;
14+
// @todo: Temporary fix a bug that prevents Chromium browsers from selecting ".heic" files
15+
// from the file upload. See https://core.trac.wordpress.org/ticket/62268#comment:4.
16+
// This can be removed once the Chromium fix is in the stable channel.
17+
// Prevent Safari from adding "image/heic" and "image/heif" to the accept attribute.
18+
- const isSafari = globalThis.window?.navigator.userAgent.includes('Safari') && !globalThis.window?.navigator.userAgent.includes('Chrome') && !globalThis.window?.navigator.userAgent.includes('Chromium');
19+
- const compatAccept = !isSafari && !!accept?.includes('image/*') ? `${accept}, image/heic, image/heif` : accept;
20+
+ if (!isSafari && !!accept?.includes('image/*')) {
21+
+ compatAccept = `${accept}, image/heic, image/heif`;
22+
+ }
23+
+ // iOS Safari's `accept` attribute lacks wildcard `audio/*` support.
24+
+ // https://stackoverflow.com/a/66859581
25+
+ if (isSafari && !!accept?.includes('audio/*')) {
26+
+ compatAccept = `${accept}, audio/mp3, audio/x-m4a, audio/x-m4b, audio/x-m4p, audio/x-wav, audio/webm`;
27+
+ }
28+
return /*#__PURE__*/_jsxs("div", {
29+
className: "components-form-file-upload",
30+
children: [ui, /*#__PURE__*/_jsx("input", {

patches/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Existing patches should be described and justified here.
1111
- Expose an `open` prop on the `Inserter` component, allowing toggling the inserter visibility via the quick inserter's "Browse all" button.
1212
- Disable `stripExperimentalSettings` in the `BlockEditorProvider` component so that the Patterns and Media inserter tabs function.
1313

14+
### `@wordpress/components`
15+
16+
- Apply workaround to `FormFileUpload` to address iOS Safari's lack of support for a wildcard `audio/*` MIME type. Can be removed once [the issue](https://github.com/WordPress/gutenberg/issues/70119) is resolved in a future release.
17+
1418
### `@wordpress/rich-text`
1519

1620
- Fix `preventFocusCapture` causing uneditable text blocks on touch devices when scrolling by swiping outside of the block canvas--e.g., along the edge of the screen.

0 commit comments

Comments
 (0)