1import type { KeyboardEvent } from "react";
2
3import { isMacPlatform } from "~/lib/utils";
4import { SubmitKbd } from "./SubmitKbd";
5
6/** The mod+Enter key cap a dialog's primary button carries. */
7export function DialogSubmitKbd() {
8 return <SubmitKbd mod />;
9}
10
11/** True for mod+Enter, the shortcut that runs a dialog's primary action from any field. */
12export function isDialogSubmitShortcut(event: KeyboardEvent): boolean {
13 if (event.key !== "Enter" || event.shiftKey || event.altKey || event.nativeEvent.isComposing) {
14 return false;
15 }
16 return isMacPlatform(navigator.platform) ? event.metaKey : event.ctrlKey;
17}