Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Balloon): v2 default offset adjustment #4987

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

Object.assign(otherProps, {
placement: align,
placementOffset: placementOffset + 12,
placementOffset: placementOffset,
v2: true,
beforePosition: this.beforePosition,
autoAdjust,
Expand All @@ -375,7 +375,7 @@
afterClose={this.props.afterClose}
onVisibleChange={this._onVisibleChange}
animation={animation}
autoFocus={triggerType === 'focus' ? false : autoFocus}

Check warning on line 378 in components/balloon/balloon.tsx

View workflow job for this annotation

GitHub Actions / changed

The autoFocus prop should not be used, as it can reduce usability and accessibility for users
safeNode={safeNode}
container={popupContainer || container}
className={popupClassName}
Expand Down
Loading