isModifierKeyPressed.tsx 480 B

12345678910111213
  1. import {isAppleDevice, isMac} from '@react-aria/utils';
  2. /**
  3. * Whether a modifier key (ctrl/alt/shift) is being pressed. Based on
  4. * https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/selection/src/utils.ts
  5. */
  6. export function isModifierKeyPressed(e: React.KeyboardEvent<HTMLDivElement>) {
  7. return (
  8. (isAppleDevice() ? e.altKey : e.ctrlKey) || // contiguous selection modifier
  9. (isMac() ? e.metaKey : e.ctrlKey) || // ctrl key
  10. e.shiftKey
  11. );
  12. }