@@ -8,9 +8,10 @@ import { composeRef } from 'rc-util/lib/ref';
88import isVisible from 'rc-util/lib/Dom/isVisible' ;
99import { alignElement , alignPoint } from 'dom-align' ;
1010import addEventListener from 'rc-util/lib/Dom/addEventListener' ;
11+ import isEqual from 'lodash/isEqual' ;
1112
1213import { isSamePoint , restoreFocus , monitorResize } from './util' ;
13- import { AlignType , AlignResult , TargetType , TargetPoint } from './interface' ;
14+ import type { AlignType , AlignResult , TargetType , TargetPoint } from './interface' ;
1415import useBuffer from './hooks/useBuffer' ;
1516
1617type OnAlign = ( source : HTMLElement , result : AlignResult ) => void ;
@@ -48,7 +49,9 @@ const Align: React.ForwardRefRenderFunction<RefAlign, AlignProps> = (
4849 { children, disabled, target, align, onAlign, monitorWindowResize, monitorBufferTime = 0 } ,
4950 ref ,
5051) => {
51- const cacheRef = React . useRef < { element ?: HTMLElement ; point ?: TargetPoint } > ( { } ) ;
52+ const cacheRef = React . useRef < { element ?: HTMLElement ; point ?: TargetPoint ; align ?: AlignType } > (
53+ { } ,
54+ ) ;
5255 const nodeRef = React . useRef ( ) ;
5356 let childNode = React . Children . only ( children ) ;
5457
@@ -57,16 +60,19 @@ const Align: React.ForwardRefRenderFunction<RefAlign, AlignProps> = (
5760 const forceAlignPropsRef = React . useRef < {
5861 disabled ?: boolean ;
5962 target ?: TargetType ;
63+ align ?: AlignType ;
6064 onAlign ?: OnAlign ;
6165 } > ( { } ) ;
6266 forceAlignPropsRef . current . disabled = disabled ;
6367 forceAlignPropsRef . current . target = target ;
68+ forceAlignPropsRef . current . align = align ;
6469 forceAlignPropsRef . current . onAlign = onAlign ;
6570
6671 const [ forceAlign , cancelForceAlign ] = useBuffer ( ( ) => {
6772 const {
6873 disabled : latestDisabled ,
6974 target : latestTarget ,
75+ align : latestAlign ,
7076 onAlign : latestOnAlign ,
7177 } = forceAlignPropsRef . current ;
7278 if ( ! latestDisabled && latestTarget ) {
@@ -78,6 +84,7 @@ const Align: React.ForwardRefRenderFunction<RefAlign, AlignProps> = (
7884
7985 cacheRef . current . element = element ;
8086 cacheRef . current . point = point ;
87+ cacheRef . current . align = latestAlign ;
8188
8289 // IE lose focus after element realign
8390 // We should record activeElement and restore later
@@ -121,7 +128,11 @@ const Align: React.ForwardRefRenderFunction<RefAlign, AlignProps> = (
121128 sourceResizeMonitor . current . cancel = monitorResize ( nodeRef . current , forceAlign ) ;
122129 }
123130
124- if ( cacheRef . current . element !== element || ! isSamePoint ( cacheRef . current . point , point ) ) {
131+ if (
132+ cacheRef . current . element !== element ||
133+ ! isSamePoint ( cacheRef . current . point , point ) ||
134+ ! isEqual ( cacheRef . current . align , align )
135+ ) {
125136 forceAlign ( ) ;
126137
127138 // Add resize observer
@@ -181,7 +192,7 @@ const Align: React.ForwardRefRenderFunction<RefAlign, AlignProps> = (
181192 return childNode ;
182193} ;
183194
184- const RefAlign = React . forwardRef ( Align ) ;
185- RefAlign . displayName = 'Align' ;
195+ const RcAlign = React . forwardRef ( Align ) ;
196+ RcAlign . displayName = 'Align' ;
186197
187- export default RefAlign ;
198+ export default RcAlign ;
0 commit comments