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

useKeyPress 在 firfox 下的兼容问题 #1467

Open
brickspert opened this issue Feb 18, 2022 · 12 comments
Open

useKeyPress 在 firfox 下的兼容问题 #1467

brickspert opened this issue Feb 18, 2022 · 12 comments
Assignees
Labels

Comments

@brickspert
Copy link
Collaborator

image

编码对应兼容性问题

@yunsii
Copy link

yunsii commented Feb 18, 2022

当前已知在 firefox 下 keyCode 有如下对应关系:

equalsign: 61
dash: 173

event.keyCode 字段已被标记为 deprecated:

image

测试发现直接使用 event.key (直接对应键盘上的符号)不用考虑浏览器兼容问题了,更不用自己去定义别名了。综上,使用 event.key.toLowerCase() 来作为判断依据应该更直观和有效。

不过如果直接这样做的话,算是破坏性更新了,还需要考虑现有别名的兼容处理,如下:

equalsign: "="
dash: "-"

最后,思路都有了,可以的话我应该能 PR 一下 😂

@yunsii
Copy link

yunsii commented Feb 18, 2022

另外现在 useKeyPress 看起来没考虑严格模式?意思是 ctrl + shift [+ alt] + A 也能触发 ctrl + A 的回调,或许也可以加个 strict 配置。

@brickspert
Copy link
Collaborator Author

Related: #1452

@brickspert
Copy link
Collaborator Author

当前已知在 firefox 下 keyCode 有如下对应关系:

equalsign: 61 dash: 173

event.keyCode 字段已被标记为 deprecated:

image

测试发现直接使用 event.key (直接对应键盘上的符号)不用考虑浏览器兼容问题了,更不用自己去定义别名了。综上,使用 event.key.toLowerCase() 来作为判断依据应该更直观和有效。

不过如果直接这样做的话,算是破坏性更新了,还需要考虑现有别名的兼容处理,如下:

equalsign: "=" dash: "-"

最后,思路都有了,可以的话我应该能 PR 一下 😂

破坏性升级不可以的,两个问题我们这边会尽快统一处理下哈。

@yunsii
Copy link

yunsii commented Feb 18, 2022

有考虑兼容处理啊,修改对应关系为 别名: key,而不是 别名: keyCode,代码中使用 event.key 来判断就好了。这样就支持别名加 key 来定义快捷键了,例如:

ctrl.equalsignctrl.= 都是可行的。

@crazylxr crazylxr self-assigned this Feb 21, 2022
@brickspert
Copy link
Collaborator Author

另外现在 useKeyPress 看起来没考虑严格模式?意思是 ctrl + shift [+ alt] + A 也能触发 ctrl + A 的回调,或许也可以加个 strict 配置。

这个已经修复了

@yunsii
Copy link

yunsii commented Mar 4, 2022

另外现在 useKeyPress 看起来没考虑严格模式?意思是 ctrl + shift [+ alt] + A 也能触发 ctrl + A 的回调,或许也可以加个 strict 配置。

这个已经修复了

看了一下代码,这是不是也可能是 break changes 呢,如果有人真期望不用严格匹配呢?:joy:

@brickspert
Copy link
Collaborator Author

你说的有道理,我们加个配置。

@brickspert
Copy link
Collaborator Author

另外现在 useKeyPress 看起来没考虑严格模式?意思是 ctrl + shift [+ alt] + A 也能触发 ctrl + A 的回调,或许也可以加个 strict 配置。

这个已经修复了

看了一下代码,这是不是也可能是 break changes 呢,如果有人真期望不用严格匹配呢?😂

3.1.13 加了 exactMatch 参数,然后默认为 false,感谢提醒。文档待会补,库已经发布了。

@crazylxr crazylxr added the help wanted Extra attention is needed label Jun 22, 2022
@crazylxr crazylxr removed their assignment Jun 22, 2022
@github-actions
Copy link

Hello @brickspert. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please send your Pull Request to proper branch (feature branch for the new feature, master for bugfix and other changes), fill the Pull Request Template here, provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution!

你好 @brickspert,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请将 Pull Request 发到正确的分支(新特性发到 feature 分支,其他发到 master 分支),务必填写 Pull Request 内的预设模板,提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。

giphy

@crazylxr crazylxr added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Jun 22, 2022
@github-actions
Copy link

Hello @brickspert. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please send your Pull Request to proper branch (feature branch for the new feature, master for bugfix and other changes), fill the Pull Request Template here, provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution!

你好 @brickspert,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请将 Pull Request 发到正确的分支(新特性发到 feature 分支,其他发到 master 分支),务必填写 Pull Request 内的预设模板,提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。

giphy

@liuyib liuyib self-assigned this Feb 23, 2023
@liuyib liuyib added next version question and removed help wanted Extra attention is needed labels Feb 23, 2023
@liuyib
Copy link
Collaborator

liuyib commented Feb 23, 2023

有计划下个 major 版本改用 e.key 方案,这会引起 breaking changes,初步讨论见评论区:#2054, 下个大版本之前会详细讨论

@liuyib liuyib added this to To do in ahooks tasks via automation Feb 23, 2023
@liuyib liuyib moved this from To do to v4 in ahooks tasks Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants