diff --git a/packages/components/src/keyboard-shortcuts/index.js b/packages/components/src/keyboard-shortcuts/index.js index d4b12867e08b6f..5bb2cee5499c63 100644 --- a/packages/components/src/keyboard-shortcuts/index.js +++ b/packages/components/src/keyboard-shortcuts/index.js @@ -10,6 +10,11 @@ import { forEach } from 'lodash'; */ import { Component, Children } from '@wordpress/element'; +/** + * Internal dependencies + */ +import { isAppleOS } from './platform'; + class KeyboardShortcuts extends Component { constructor() { super( ...arguments ); @@ -30,8 +35,10 @@ class KeyboardShortcuts extends Component { const hasShift = modifiers.has( 'shift' ); if ( - ( modifiers.size === 1 && hasAlt ) || - ( modifiers.size === 2 && hasAlt && hasShift ) + isAppleOS() && ( + ( modifiers.size === 1 && hasAlt ) || + ( modifiers.size === 2 && hasAlt && hasShift ) + ) ) { throw new Error( `Cannot bind ${ key }. Alt and Shift+Alt modifiers are reserved for character input.` ); } diff --git a/packages/components/src/keyboard-shortcuts/platform.js b/packages/components/src/keyboard-shortcuts/platform.js new file mode 100644 index 00000000000000..386f0d7fb173f9 --- /dev/null +++ b/packages/components/src/keyboard-shortcuts/platform.js @@ -0,0 +1,18 @@ +/** + * External dependencies + */ +import { includes } from 'lodash'; + +/** + * Return true if platform is MacOS. + * + * @param {Object} _window window object by default; used for DI testing. + * + * @return {boolean} True if MacOS; false otherwise. + */ +export function isAppleOS( _window = window ) { + const { platform } = _window.navigator; + + return platform.indexOf( 'Mac' ) !== -1 || + includes( [ 'iPad', 'iPhone' ], platform ); +}