Skip to content

Bug: (Macos) pressing cmd+c or any shortcut that has cmd in it will break any registered shortcuts unless the window goes blur #576

Description

@whoami-amrit

Suppose we have a sample app like below. Assume <App /> is wrapped with <ShortcutProvider>

Sample application. Please click me!
import { useState, useEffect } from 'react'
import { useShortcut } from 'react-keybind'
import './App.css'

function App() {
    const [show, setShow] = useState(false)
    const { registerShortcut, unregisterShortcut } = useShortcut()

    console.log('hello')

    const handleShortcut = (e) => {
        console.log(e)
        setShow((prev) => !prev)
    }

    useEffect(() => {
        registerShortcut(handleShortcut, ['k'], 'show', 'show') 

        return () => {
            unregisterShortcut(['k'])
        }
        // eslint-disable-next-line
    }, [])

    return show ? (
        <h1>Shown</h1>
    ) : (
        <h1>Not shown</h1>
    )
}

export default App

If I press the cmd key or press cmd+c, the registered shortcut 'k' stops working. This is not the case in Windows though.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions