-
-
Notifications
You must be signed in to change notification settings - Fork 105
chore: adjust keyboard event handling logic #558
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,12 +15,13 @@ import type { DrawerClassNames, DrawerStyles } from './inter'; | |
| export type Placement = 'left' | 'top' | 'right' | 'bottom'; | ||
|
|
||
| export interface DrawerProps | ||
| extends Omit<DrawerPopupProps, 'prefixCls' | 'inline' | 'scrollLocker'>, | ||
| extends | ||
| Omit<DrawerPopupProps, 'prefixCls' | 'inline' | 'scrollLocker'>, | ||
| DrawerPanelEvents, | ||
| DrawerPanelAccessibility { | ||
| prefixCls?: string; | ||
| open?: boolean; | ||
| onClose?: (e: React.MouseEvent | React.KeyboardEvent) => void; | ||
| onClose?: (e: React.MouseEvent | React.KeyboardEvent | KeyboardEvent) => void; | ||
| destroyOnHidden?: boolean; | ||
| getContainer?: PortalProps['getContainer']; | ||
| panelRef?: React.Ref<HTMLDivElement>; | ||
|
|
@@ -73,6 +74,7 @@ const Drawer: React.FC<DrawerProps> = props => { | |
| onClick, | ||
| onKeyDown, | ||
| onKeyUp, | ||
| onClose, | ||
| resizable, | ||
| defaultSize, | ||
|
|
||
|
|
@@ -159,13 +161,21 @@ const Drawer: React.FC<DrawerProps> = props => { | |
| ...eventHandlers, | ||
| }; | ||
|
|
||
| const onEsc: PortalProps['onEsc'] = ({ top, event }) => { | ||
| if (top && keyboard) { | ||
| event.stopPropagation(); | ||
| onClose?.(event); | ||
| } | ||
| }; | ||
|
Comment on lines
+164
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # 查找 src/Drawer.tsx 文件并查看目标行
fd -type f "Drawer.tsx" -path "*/src/*" | head -5Repository: react-component/drawer Length of output: 236 🏁 Script executed: # 检查 @rc-component/portal 包是否存在及其结构
ls -la node_modules/@rc-component/portal 2>/dev/null | head -20Repository: react-component/drawer Length of output: 48 🏁 Script executed: # 正确的查找命令 - 查找 Drawer.tsx
fd "Drawer.tsx" src/Repository: react-component/drawer Length of output: 80 🏁 Script executed: # 查看项目结构
ls -la src/ | head -20Repository: react-component/drawer Length of output: 675 🏁 Script executed: # 查找所有 TypeScript 文件中 onEsc 的引用
rg "onEsc" --type ts --type tsxRepository: react-component/drawer Length of output: 93 🏁 Script executed: # 查看 Drawer.tsx 的内容,特别关注行 164-169
cat -n src/Drawer.tsx | sed -n '150,180p'Repository: react-component/drawer Length of output: 1000 🏁 Script executed: # 搜索 onEsc 的使用(不指定文件类型)
rg "onEsc" -A 5 -B 2Repository: react-component/drawer Length of output: 686 🏁 Script executed: # 查看 Drawer.tsx 的导入部分
head -40 src/Drawer.tsxRepository: react-component/drawer Length of output: 1501 🏁 Script executed: # 搜索 PortalProps 的定义或使用
rg "PortalProps" -B 2 -A 5Repository: react-component/drawer Length of output: 1158 🏁 Script executed: # 查看 package.json 了解依赖信息
cat package.json | grep -A 2 -B 2 "portal\|Portal"Repository: react-component/drawer Length of output: 218 🏁 Script executed: # 查找项目中所有的 d.ts 或 TypeScript 定义文件
find . -name "*.d.ts" -o -name "*.ts" | grep -i portal | head -10Repository: react-component/drawer Length of output: 48 🏁 Script executed: # 查看是否有 node_modules,并检查 @rc-component/portal 的类型文件
find . -path "*/node_modules/@rc-component/portal*" -name "*.d.ts" 2>/dev/null | head -5Repository: react-component/drawer Length of output: 48 🌐 Web query:
💡 Result: Short answer: @rc-component/portal does not expose an onEsc prop. Its documented props are getContainer, open, and autoLock; it provides no built‑in Escape-key handler — handle Escape yourself (e.g., add a keydown listener in your portal content or use a higher-level component like rc-dialog that supports onClose). [1][2] Sources:
🌐 Web query:
💡 Result: Short answer: No — @rc-component/portal v2.x does not include a built-in onEsc/escape-key prop. The published API shows only props like getContainer, open and autoLock (no onEsc/close-on-esc). See the package README/API. [1][2] If you need ESC-to-close behavior, add a keydown listener in your component that wraps Portal (or use a higher-level rc component that provides built-in close-on-esc). [1] Sources:
🌐 Web query:
💡 Result: Do you mean the GitHub repo react-component/portal (or the npm package @rc-component/portal)? Do you want to know whether a 2024 release added an onEsc (escape-key) prop/feature? 🏁 Script executed: # 查找是否有其他 Portal 使用的例子
rg "Portal" src/ -B 2 -A 5 | head -50Repository: react-component/drawer Length of output: 2096 🏁 Script executed: # 查看项目的 tsconfig 或相关配置,检查是否有类型覆盖
cat tsconfig.json 2>/dev/null || echo "No tsconfig.json"Repository: react-component/drawer Length of output: 450 Portal 不支持 onEsc 属性,此实现将无法工作。 根据官方文档, 建议采用以下替代方案之一:
|
||
|
|
||
| return ( | ||
| <RefContext.Provider value={refContext}> | ||
| <Portal | ||
| open={mergedOpen || forceRender || animatedVisible} | ||
| autoDestroy={false} | ||
| getContainer={getContainer} | ||
| autoLock={mask && (mergedOpen || animatedVisible)} | ||
| onEsc={onEsc} | ||
| > | ||
| <DrawerPopup {...drawerPopupProps} /> | ||
| </Portal> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've correctly updated the
onClosetype here to includeKeyboardEvent. However, theonCloseprop in theDrawerPopupPropsinterface (defined insrc/DrawerPopup.tsx) was not updated to reflect this change. This creates a type inconsistency between theDrawerandDrawerPopupcomponents, which can lead to type errors under stricter TypeScript configurations (likestrictFunctionTypes). To ensure type safety,DrawerPopupProps['onClose']should also be updated to accept a nativeKeyboardEvent.