@@ -195,6 +195,8 @@ const Preview: React.FC<PreviewProps> = props => {
195195 } = props ;
196196
197197 const imgRef = useRef < HTMLImageElement > ( ) ;
198+ const wrapperRef = useRef < HTMLDivElement > ( null ) ;
199+ const lastActiveRef = useRef < HTMLElement | null > ( null ) ;
198200 const groupContext = useContext ( PreviewGroupContext ) ;
199201 const showLeftOrRightSwitches = groupContext && count > 1 ;
200202 const showOperationsProgress = groupContext && count >= 1 ;
@@ -239,6 +241,20 @@ const Preview: React.FC<PreviewProps> = props => {
239241 }
240242 } , [ open ] ) ;
241243
244+ // =========================== Focus ============================
245+ useEffect ( ( ) => {
246+ if ( open ) {
247+ lastActiveRef . current = ( document . activeElement as HTMLElement ) || null ;
248+
249+ if ( wrapperRef . current ) {
250+ wrapperRef . current . focus ( ) ;
251+ }
252+ } else if ( ! open && lastActiveRef . current ) {
253+ lastActiveRef . current . focus ( ) ;
254+ lastActiveRef . current = null ;
255+ }
256+ } , [ open ] ) ;
257+
242258 // ========================== Image ===========================
243259 const onDoubleClick = ( event : React . MouseEvent < HTMLImageElement , MouseEvent > ) => {
244260 if ( open ) {
@@ -418,10 +434,15 @@ const Preview: React.FC<PreviewProps> = props => {
418434
419435 return (
420436 < div
437+ ref = { wrapperRef }
421438 className = { clsx ( prefixCls , rootClassName , classNames . root , motionClassName , {
422439 [ `${ prefixCls } -moving` ] : isMoving ,
423440 } ) }
424441 style = { mergedStyle }
442+ role = "dialog"
443+ aria-modal = "true"
444+ aria-label = { alt || 'Image preview' }
445+ tabIndex = { - 1 }
425446 >
426447 { /* Mask */ }
427448 < div
0 commit comments