diff --git a/src/DrawerPanel.tsx b/src/DrawerPanel.tsx index 619e4146..5be8c950 100644 --- a/src/DrawerPanel.tsx +++ b/src/DrawerPanel.tsx @@ -1,8 +1,6 @@ import * as React from 'react'; import classNames from 'classnames'; import type { Placement } from './Drawer'; -import KeyCode from 'rc-util/lib/KeyCode'; -import { composeRef } from 'rc-util/lib/ref'; export interface DrawerPanelRef { focus: VoidFunction; @@ -16,121 +14,48 @@ export interface DrawerPanelProps { height?: number | string; placement: Placement; children?: React.ReactNode; - onClose?: React.KeyboardEventHandler; containerRef?: React.Ref; } -const sentinelStyle: React.CSSProperties = { - width: 0, - height: 0, - overflow: 'hidden', - outline: 'none', - position: 'absolute', +const DrawerPanel = (props: DrawerPanelProps) => { + const { + prefixCls, + className, + style, + placement, + width, + height, + children, + containerRef, + } = props; + + // =============================== Render =============================== + const panelStyle: React.CSSProperties = {}; + + if (placement === 'left' || placement === 'right') { + panelStyle.width = width; + } else { + panelStyle.height = height; + } + + return ( + <> +
+ {children} +
+ + ); }; -const DrawerPanel = React.forwardRef( - (props, ref) => { - const { - prefixCls, - className, - style, - placement, - width, - height, - children, - onClose, - containerRef, - } = props; - - // ================================ Refs ================================ - const panelRef = React.useRef(); - const sentinelStartRef = React.useRef(); - const sentinelEndRef = React.useRef(); - - React.useImperativeHandle(ref, () => ({ - focus: () => { - Promise.resolve().then(() => { - sentinelStartRef.current?.focus({ preventScroll: true }); - }); - }, - })); - - const onPanelKeyDown: React.KeyboardEventHandler< - HTMLDivElement - > = event => { - const { keyCode, shiftKey } = event; - - switch (keyCode) { - // Tab active - case KeyCode.TAB: { - if (keyCode === KeyCode.TAB) { - if ( - !shiftKey && - document.activeElement === sentinelEndRef.current - ) { - sentinelStartRef.current?.focus({ preventScroll: true }); - } else if ( - shiftKey && - document.activeElement === sentinelStartRef.current - ) { - sentinelEndRef.current?.focus({ preventScroll: true }); - } - } - break; - } - - // Close - case KeyCode.ESC: { - onClose(event); - break; - } - } - }; - - // =============================== Render =============================== - const panelStyle: React.CSSProperties = {}; - - if (placement === 'left' || placement === 'right') { - panelStyle.width = width; - } else { - panelStyle.height = height; - } - - return ( - <> -
-