Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent default behaviour #8

Open
awqsomee opened this issue Nov 30, 2023 · 0 comments
Open

Prevent default behaviour #8

awqsomee opened this issue Nov 30, 2023 · 0 comments

Comments

@awqsomee
Copy link

When pressing Ctrl+K it follows the standard behavior of the browser, neither fn nor target are triggered.

const $isModalOpen = createStore(false)

const ctrlKPressed = hotkey({ key: 'Ctrl+KeyC' })
const openSearch = createEvent()
const preventDefaultFx = createEffect((evt: KeyboardEvent) => evt.preventDefault())

sample({
    clock: [ctrlKPressed, openSearch],
    fn: (evt) => {
        if (evt instanceof KeyboardEvent) evt.preventDefault()
        return true
    },
    target: [$isModalOpen, preventDefaultFx],
})

so none of the preventDefault methods break the standard behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant