Skip to content

Commit 3cf4307

Browse files
fix(ui): Prevent Command from triggering while a editable field has focus (medusajs#11254)
Resolves CMRC-909
1 parent f07af7b commit 3cf4307

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

.changeset/spicy-bees-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/ui": patch
3+
---
4+
5+
fix(ui): Prevent Command from triggering while a editable field has focus"

packages/design-system/ui/src/components/command-bar/command-bar.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as React from "react"
55

66
import { Kbd } from "@/components/kbd"
77
import { clx } from "@/utils/clx"
8+
import { isInputElement } from "@/utils/is-input-element"
89

910
interface CommandBarProps extends React.PropsWithChildren {
1011
open?: boolean
@@ -166,6 +167,10 @@ const Command = React.forwardRef<HTMLButtonElement, CommandProps>(
166167
) => {
167168
React.useEffect(() => {
168169
const handleKeyDown = (event: KeyboardEvent) => {
170+
if (isInputElement(document.activeElement)) {
171+
return
172+
}
173+
169174
if (event.key.toLowerCase() === shortcut.toLowerCase()) {
170175
event.preventDefault()
171176
event.stopPropagation()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const isInputElement = (element: Element | null): boolean => {
2+
return (
3+
element instanceof HTMLElement &&
4+
(element.isContentEditable ||
5+
element.tagName === "INPUT" ||
6+
element.tagName === "TEXTAREA" ||
7+
element.tagName === "SELECT")
8+
)
9+
}
10+
11+
export { isInputElement }

0 commit comments

Comments
 (0)