fix(ui): Prevent Command from triggering while a editable field has focus (#11254)
Resolves CMRC-909
This commit is contained in:
1 parent
f07af7b93c
commit
3cf4307296
3 files changed
+21
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/ui": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(ui): Prevent Command from triggering while a editable field has focus"
|
||||||
@@ -5,6 +5,7 @@ import * as React from "react"
|
|||||||
|
|
||||||
import { Kbd } from "@/components/kbd"
|
import { Kbd } from "@/components/kbd"
|
||||||
import { clx } from "@/utils/clx"
|
import { clx } from "@/utils/clx"
|
||||||
|
import { isInputElement } from "@/utils/is-input-element"
|
||||||
|
|
||||||
interface CommandBarProps extends React.PropsWithChildren {
|
interface CommandBarProps extends React.PropsWithChildren {
|
||||||
open?: boolean
|
open?: boolean
|
||||||
@@ -166,6 +167,10 @@ const Command = React.forwardRef<HTMLButtonElement, CommandProps>(
|
|||||||
) => {
|
) => {
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (isInputElement(document.activeElement)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key.toLowerCase() === shortcut.toLowerCase()) {
|
if (event.key.toLowerCase() === shortcut.toLowerCase()) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|||||||
@@ -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 }
|
||||||
Reference in new issue
Block a user