Skip to content

Commit 700780f

Browse files
authored
fix: transform support one is 0 (#434)
1 parent 747f00a commit 700780f

File tree

2 files changed

+53
-35
lines changed

2 files changed

+53
-35
lines changed

src/Dialog/Content/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
4141
const elementOffset = offset(dialogRef.current);
4242

4343
setTransformOrigin(
44-
(mousePosition?.x && mousePosition?.y)
44+
mousePosition && (mousePosition.x || mousePosition.y)
4545
? `${mousePosition.x - elementOffset.left}px ${mousePosition.y - elementOffset.top}px`
4646
: '',
4747
);

tests/index.spec.tsx

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -280,24 +280,48 @@ describe('dialog', () => {
280280
});
281281
});
282282

283-
it('sets transform-origin when property mousePosition is set', () => {
284-
const wrapper = mount(
285-
<Dialog style={{ width: 600 }} mousePosition={{ x: 100, y: 100 }} visible>
286-
<p>the dialog</p>
287-
</Dialog>,
288-
);
283+
describe('mousePosition', () => {
284+
function prepareModal(mousePosition: { x: number; y: number }) {
285+
const wrapper = mount(
286+
<Dialog style={{ width: 600 }} mousePosition={mousePosition} visible>
287+
<p>the dialog</p>
288+
</Dialog>,
289+
);
290+
291+
// Trigger position align
292+
act(() => {
293+
wrapper
294+
.find<any>('Content CSSMotion' as any)
295+
.props()
296+
.onAppearPrepare();
297+
});
298+
299+
return wrapper;
300+
}
301+
302+
it('sets transform-origin when property mousePosition is set', () => {
303+
const wrapper = prepareModal({ x: 100, y: 100 });
304+
305+
expect(
306+
(wrapper.find('.rc-dialog').at(0).getDOMNode() as HTMLDivElement).style['transform-origin'],
307+
).toBeTruthy();
308+
});
289309

290-
// Trigger position align
291-
act(() => {
292-
wrapper
293-
.find<any>('Content CSSMotion' as any)
294-
.props()
295-
.onAppearPrepare();
310+
it('both undefined', () => {
311+
const wrapper = prepareModal({ x: undefined, y: undefined });
312+
313+
expect(
314+
(wrapper.find('.rc-dialog').at(0).getDOMNode() as HTMLDivElement).style['transform-origin'],
315+
).toBeFalsy();
296316
});
297317

298-
expect(
299-
(wrapper.find('.rc-dialog').at(0).getDOMNode() as HTMLDivElement).style['transform-origin'],
300-
).toBeTruthy();
318+
it('one valid', () => {
319+
const wrapper = prepareModal({ x: 10, y: 0 });
320+
321+
expect(
322+
(wrapper.find('.rc-dialog').at(0).getDOMNode() as HTMLDivElement).style['transform-origin'],
323+
).toBeTruthy();
324+
});
301325
});
302326

303327
it('can get dom element before dialog first show when forceRender is set true ', () => {
@@ -644,14 +668,14 @@ describe('dialog', () => {
644668
it('support aria-* in closable', () => {
645669
const onClose = jest.fn();
646670
const wrapper = mount(
647-
<Dialog
671+
<Dialog
648672
closable={{
649-
closeIcon:"test",
673+
closeIcon: 'test',
650674
'aria-label': 'test aria-label',
651-
}}
652-
visible
653-
onClose={onClose}
654-
/>
675+
}}
676+
visible
677+
onClose={onClose}
678+
/>,
655679
);
656680
jest.runAllTimers();
657681
wrapper.update();
@@ -669,14 +693,14 @@ describe('dialog', () => {
669693
it('support disable button in closable', () => {
670694
const onClose = jest.fn();
671695
const wrapper = mount(
672-
<Dialog
696+
<Dialog
673697
closable={{
674-
closeIcon:"test",
698+
closeIcon: 'test',
675699
disabled: true,
676-
}}
677-
visible
678-
onClose={onClose}
679-
/>
700+
}}
701+
visible
702+
onClose={onClose}
703+
/>,
680704
);
681705
jest.runAllTimers();
682706
wrapper.update();
@@ -697,13 +721,7 @@ describe('dialog', () => {
697721

698722
it('should not display closeIcon when closable is false', () => {
699723
const onClose = jest.fn();
700-
const wrapper = mount(
701-
<Dialog
702-
closable={false}
703-
visible
704-
onClose={onClose}
705-
/>
706-
);
724+
const wrapper = mount(<Dialog closable={false} visible onClose={onClose} />);
707725
jest.runAllTimers();
708726
wrapper.update();
709727

0 commit comments

Comments
 (0)