Skip to content

Commit

Permalink
fix: transform support one is 0 (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Jun 6, 2024
1 parent 747f00a commit 700780f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Dialog/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
const elementOffset = offset(dialogRef.current);

setTransformOrigin(
(mousePosition?.x && mousePosition?.y)
mousePosition && (mousePosition.x || mousePosition.y)
? `${mousePosition.x - elementOffset.left}px ${mousePosition.y - elementOffset.top}px`
: '',
);
Expand Down
86 changes: 52 additions & 34 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,48 @@ describe('dialog', () => {
});
});

it('sets transform-origin when property mousePosition is set', () => {
const wrapper = mount(
<Dialog style={{ width: 600 }} mousePosition={{ x: 100, y: 100 }} visible>
<p>the dialog</p>
</Dialog>,
);
describe('mousePosition', () => {
function prepareModal(mousePosition: { x: number; y: number }) {
const wrapper = mount(
<Dialog style={{ width: 600 }} mousePosition={mousePosition} visible>
<p>the dialog</p>
</Dialog>,
);

// Trigger position align
act(() => {
wrapper
.find<any>('Content CSSMotion' as any)
.props()
.onAppearPrepare();
});

return wrapper;
}

it('sets transform-origin when property mousePosition is set', () => {
const wrapper = prepareModal({ x: 100, y: 100 });

expect(
(wrapper.find('.rc-dialog').at(0).getDOMNode() as HTMLDivElement).style['transform-origin'],
).toBeTruthy();
});

// Trigger position align
act(() => {
wrapper
.find<any>('Content CSSMotion' as any)
.props()
.onAppearPrepare();
it('both undefined', () => {
const wrapper = prepareModal({ x: undefined, y: undefined });

expect(
(wrapper.find('.rc-dialog').at(0).getDOMNode() as HTMLDivElement).style['transform-origin'],
).toBeFalsy();
});

expect(
(wrapper.find('.rc-dialog').at(0).getDOMNode() as HTMLDivElement).style['transform-origin'],
).toBeTruthy();
it('one valid', () => {
const wrapper = prepareModal({ x: 10, y: 0 });

expect(
(wrapper.find('.rc-dialog').at(0).getDOMNode() as HTMLDivElement).style['transform-origin'],
).toBeTruthy();
});
});

it('can get dom element before dialog first show when forceRender is set true ', () => {
Expand Down Expand Up @@ -644,14 +668,14 @@ describe('dialog', () => {
it('support aria-* in closable', () => {
const onClose = jest.fn();
const wrapper = mount(
<Dialog
<Dialog
closable={{
closeIcon:"test",
closeIcon: 'test',
'aria-label': 'test aria-label',
}}
visible
onClose={onClose}
/>
}}
visible
onClose={onClose}
/>,
);
jest.runAllTimers();
wrapper.update();
Expand All @@ -669,14 +693,14 @@ describe('dialog', () => {
it('support disable button in closable', () => {
const onClose = jest.fn();
const wrapper = mount(
<Dialog
<Dialog
closable={{
closeIcon:"test",
closeIcon: 'test',
disabled: true,
}}
visible
onClose={onClose}
/>
}}
visible
onClose={onClose}
/>,
);
jest.runAllTimers();
wrapper.update();
Expand All @@ -697,13 +721,7 @@ describe('dialog', () => {

it('should not display closeIcon when closable is false', () => {
const onClose = jest.fn();
const wrapper = mount(
<Dialog
closable={false}
visible
onClose={onClose}
/>
);
const wrapper = mount(<Dialog closable={false} visible onClose={onClose} />);
jest.runAllTimers();
wrapper.update();

Expand Down

0 comments on commit 700780f

Please sign in to comment.