Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: stop preventing escape for radix components (#2550)

Bogdan Chadkinf94d1816af52
diff --git a/apps/builder/app/builder/shared/commands.ts b/apps/builder/app/builder/shared/commands.ts
index 916dda4d41..248aab061b 100644
--- a/apps/builder/app/builder/shared/commands.ts
+++ b/apps/builder/app/builder/shared/commands.ts
@@ -87,6 +87,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "cancelCurrentDrag",
defaultHotkeys: ["escape"],
+ // radix check event.defaultPrevented before invoking callbacks
+ preventDefault: false,
handler: () => {
const { publish } = $publisher.get();
publish?.({ type: "cancelCurrentDrag" });
diff --git a/apps/builder/app/shared/commands-emitter.ts b/apps/builder/app/shared/commands-emitter.ts
index 3b5d8cfb2f..7bb8a5b8e1 100644
--- a/apps/builder/app/shared/commands-emitter.ts
+++ b/apps/builder/app/shared/commands-emitter.ts
@@ -8,6 +8,8 @@ type CommandMeta<CommandName extends string> = {
name: CommandName;
/** default because hotkeys can be customized from ui */
defaultHotkeys?: string[];
+ /** set to false when default browser or radix behavior is desired */
+ preventDefault?: boolean;
/** listen hotkeys only locally without sharing with other apps */
disableHotkeyOutsideApp?: boolean;
/**
@@ -125,6 +127,7 @@ export const createCommandsEmitter = <CommandName extends string>({
});
const handleKeyDown = (event: KeyboardEvent) => {
let emitted = false;
+ let preventDefault = true;
for (const commandMeta of findCommandsMatchingHeaviestHotkeys()) {
if (
commandMeta.disableHotkeyOutsideApp &&
@@ -158,11 +161,15 @@ export const createCommandsEmitter = <CommandName extends string>({
continue;
}
emitted = true;
+ if (commandMeta.preventDefault === false) {
+ preventDefault = false;
+ }
emitCommand(commandMeta.name as CommandName);
}
// command can redefine browser hotkeys
- // always prevent to avoid unexpected behavior
- if (emitted) {
+ // prevent to avoid unexpected behavior
+ // unless at least one matching command disabled prevent default
+ if (emitted && preventDefault) {
event.preventDefault();
}
};