Skip to content

Commit

Permalink
fix(Badge): set alignment by use transform
Browse files Browse the repository at this point in the history
  • Loading branch information
caozhong1996 authored and zyliang96 committed Dec 6, 2024
1 parent b7e51de commit 7984dca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions components/badge/__tests__/index-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,37 @@ describe('Badge', () => {
cy.mount(<Badge count={0} showZero />);
cy.get('.next-badge-count.next-badge-scroll-number');
});

it('should on right when children is block', () => {
cy.mount(
<Badge count={1}>
<div
style={{
width: '200px',
height: '40px',
display: 'block',
background: 'blue',
}}
></div>
</Badge>
);
cy.get('.next-badge-count').then($el => {
$el.css({
transition: 'none',
animation: 'none',
});
});
cy.get('.next-badge-count').then($el => {
const targetRect = $el[0].getBoundingClientRect();
const badgeRect = document.querySelector('.next-badge')!.getBoundingClientRect();
const position = {
left: Math.round(targetRect.left),
top: Math.round(targetRect.top),
};
expect(position).to.deep.equal({
left: Math.round(badgeRect.left + badgeRect.width - targetRect.width / 2),
top: Math.round(badgeRect.top - 4),
});
});
});
});
2 changes: 2 additions & 0 deletions components/badge/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
z-index: 10;
overflow: hidden;
transform-origin: left center;
transform: translateX(50%);
right: 0;
}

&-scroll-number-only {
Expand Down

0 comments on commit 7984dca

Please sign in to comment.