'Space'-shortcut overrides native behavior triggering focused elements
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 56/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- react, typescript
- 领域
- frontend
调研方向
从链接的 CodeSandbox 开始,跟踪 useHotkey('Space', ...) 如何处理获得焦点的元素,尤其是 document.activeElement。当 Space 为表现得像按钮的获得焦点的元素保留原生激活行为,同时在没有任何相关元素获得焦点时仍触发快捷键时,修改就完成了;考虑 Enter 是否具有相同的行为。
由索引模型根据 Issue 内容生成。
描述
TanStack Hotkeys version
0.10.0
Framework/Library version
React 18.3.1
Describe the bug and the steps to reproduce it
Issue:
The space key can be used (at least on Mac) to trigger a focussed element such as a button.
The smart default (smart default: false for Mod+S, true for single keys) doesn't take this behavior into account.
This means once a useHotkey('Space',...-shortcut is set up this behavior is lost.
Likely a similar case for the "Enter"-key
Expected behavior:
It should make an exception for button-like (buttons, checkboxes, links, etc.) to preserve native behavior. i.e. "click" the button if focused, even if a 'Short'-hotkey is set.
My workaround:
const isNothingFocused = () => {
return document.activeElement === document.body || document.activeElement === null;
};
useHotkey('Space', () => {
if (isNothingFocused()) {
doSomeAction();
} else {
// Allow space for confirmation
(document.activeElement as HTMLElement)?.click();
}
});
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
https://codesandbox.io/p/sandbox/stoic-snyder-59xd9x
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
No, because I do not know how or whether it follows your design principles
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- 主要语言
- TypeScript
- 星标
- 729
- 派生
- 47
- 平均合并
- 18 小时 46 分钟
- 30 天内合并 PR
- 9
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/hotkeys 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
TanStack/hotkeys#105 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 50/100
TanStack/hotkeys#143 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 55/100
TanStack/hotkeys#138 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
维护者通常 1 天内回复
相似的 Issue
-
refactor
难度 2/5 半天 新手友好度 84/100
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
OHDSI/Data2Evidence#3450 ·
维护者通常 2 天内回复
-
e2e-failure ready-to-code
难度 2/5 1-3 小时 新手友好度 90/100
redhat-developer/rhdh-plugin-export-overlays#4011 · 1 条评论 ·
维护者通常 1 天内回复
-
automation missing-model model-sync provider:ofox
难度 2/5 1-3 小时 新手友好度 72/100
anomalyco/models.dev#8421 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复