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

getHotkeyHandler typing seems off #5705

Closed
1 of 2 tasks
tchapi opened this issue Feb 2, 2024 · 2 comments
Closed
1 of 2 tasks

getHotkeyHandler typing seems off #5705

tchapi opened this issue Feb 2, 2024 · 2 comments
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@tchapi
Copy link

tchapi commented Feb 2, 2024

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.5.1

What package has an issue?

@mantine/core

What framework do you use?

create-react-app (CRA)

In which browsers you can reproduce the issue?

All

Describe the bug

Hi 👋🏼

When using the basic example from the useHotkeys documentation here, but just making hotkeys a const in the component and passing it to getHotkeyHandler, like so:

import { TextInput } from "@mantine/core";
import { HotkeyItem, getHotkeyHandler, useHotkeys } from "@mantine/hooks";
import { notifications } from "@mantine/notifications";
import { useState } from "react";

function Demo() {
  const [value, setValue] = useState("I've just used a hotkey to send a message");
  const handleSubmit = () => notifications.show({ title: "Your message", message: value });

  const hotkeys: HotkeyItem[] = [["mod+Enter", handleSubmit]];

  return (
    <TextInput
      label="Press ⌘+Enter or Ctrl+Enter when input has focus to send message"
      value={value}
      onChange={(event) => setValue(event.target.value)}
      onKeyDown={getHotkeyHandler(hotkeys)}
    />
  );
}

.. then the following error is shown: Argument of type 'import("/...node_modules/@mantine/hooks/lib/use-hotkeys/use-hotkeys").HotkeyItem[]' is not assignable to parameter of type 'HotkeyItem[]'.

Screenshot 2024-02-02 at 11 21 54

This looks similar to #4404 but the mitigation doesn't seem to be working, as the official example shows.

I couldn't find a way to make the error disappear, even by trying to type everything correctly (event and the like).

Thanks a lot!

If possible, include a link to a codesandbox with a minimal reproduction

No response

Possible fix

It seems HotkeyItem is defined twice, but differently in your code : here, not exported, here and exported, and they seem to be conflicting if I understand correctly?

Self-service

  • I would be willing to implement a fix for this issue
@shinnik
Copy link

shinnik commented Feb 15, 2024

Hi! I had the same issue in my code, but managed to mitigate it using a type derivation directly from getHotkeyHandler:
const hotkeys: Parameters<typeof getHotkeyHandler>[0] = [["mod+Enter", handleSubmit]];

Yeah, it looks weird, but it worked for me :)

@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Feb 16, 2024
@rtivital
Copy link
Member

Fixed in 7.5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

3 participants