fix(ui): Prevent Command from triggering while a editable field has focus (#11254)

Resolves CMRC-909
This commit is contained in:
Kasper Fabricius Kristensen
2025-02-04 11:09:07 +01:00
committed by GitHub
parent f07af7b93c
commit 3cf4307296
3 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/ui": patch
---
fix(ui): Prevent Command from triggering while a editable field has focus"

View File

@@ -5,6 +5,7 @@ import * as React from "react"
import { Kbd } from "@/components/kbd"
import { clx } from "@/utils/clx"
import { isInputElement } from "@/utils/is-input-element"
interface CommandBarProps extends React.PropsWithChildren {
open?: boolean
@@ -166,6 +167,10 @@ const Command = React.forwardRef<HTMLButtonElement, CommandProps>(
) => {
React.useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (isInputElement(document.activeElement)) {
return
}
if (event.key.toLowerCase() === shortcut.toLowerCase()) {
event.preventDefault()
event.stopPropagation()

View File

@@ -0,0 +1,11 @@
const isInputElement = (element: Element | null): boolean => {
return (
element instanceof HTMLElement &&
(element.isContentEditable ||
element.tagName === "INPUT" ||
element.tagName === "TEXTAREA" ||
element.tagName === "SELECT")
)
}
export { isInputElement }