Skip to content

Commit

Permalink
fix(Balloon): v2 default offset adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
eternalsky committed Nov 27, 2024
1 parent c1dd9d8 commit 4403727
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions components/balloon/__tests__/balloon-v2-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,51 @@ describe('Balloon v2', () => {
);
cy.get('span').should('have.length', 1);
});

it('default offset should be 12px', () => {
const trigger = (
<div className="trigger" style={{ margin: '200px', display: 'inline-block' }}>
trigger
</div>
);
cy.mount(
<Balloon v2 visible trigger={trigger}>
trigger
</Balloon>
).as('Demo');
cy.get('.trigger').then($el => {
const triggerRect = $el[0].getBoundingClientRect();
expect(Math.round(triggerRect.bottom + 12)).to.equal(
Math.round(document.querySelector('.next-balloon')!.getBoundingClientRect().top)
);
});
cy.rerender('Demo', { align: 't' });
cy.get('.trigger').then($el => {
const triggerRect = $el[0].getBoundingClientRect();
expect(Math.round(triggerRect.top - 12)).to.equal(
Math.round(
document.querySelector('.next-balloon')!.getBoundingClientRect().bottom
)
);
});
cy.rerender('Demo', { align: 'l' });
cy.get('.trigger').then($el => {
const triggerRect = $el[0].getBoundingClientRect();
expect(Math.round(triggerRect.left - 12)).to.equal(
Math.round(
document.querySelector('.next-balloon')!.getBoundingClientRect().right
)
);
});
cy.rerender('Demo', { align: 'r' });
cy.get('.trigger').then($el => {
const triggerRect = $el[0].getBoundingClientRect();
expect(Math.round(triggerRect.right + 12)).to.equal(
Math.round(
document.querySelector('.next-balloon')!.getBoundingClientRect().left
)
);
});
});
});
});
2 changes: 1 addition & 1 deletion components/balloon/balloon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class Balloon extends React.Component<BalloonProps, BalloonState> {

Object.assign(otherProps, {
placement: align,
placementOffset: placementOffset + 12,
placementOffset: placementOffset,
v2: true,
beforePosition: this.beforePosition,
autoAdjust,
Expand Down

0 comments on commit 4403727

Please sign in to comment.