Skip to content
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
9 changes: 9 additions & 0 deletions src/components/progress-bar/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ describe('ProgressBar', () => {
const fillBar = screen.getByRole('progressbar').children[0];
expect(fillBar).toHaveStyle({ width: '25%' });
});

it('percentage가 100을 초과할 경우 100%로 제한되는지 확인', () => {
render(<ProgressBar percentage={150} />);
const progressbar = screen.getByRole('progressbar');
const fillBar = progressbar.children[0];

expect(progressbar).toHaveAttribute('aria-valuenow', '100');
expect(fillBar).toHaveStyle({ width: '100%' });
});
});
6 changes: 4 additions & 2 deletions src/components/progress-bar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ function ProgressBar({
const fillColor =
color || (isPast ? 'bg-gray-dark-02' : 'bg-green-normal-01');

const limitedPercentage = Math.min(100, Math.max(0, percentage));

return (
<div
role="progressbar"
aria-valuenow={percentage}
aria-valuenow={limitedPercentage}
aria-valuemin={0}
aria-valuemax={100}
className={`h-1 w-full rounded-md bg-gray-normal-01 ${className || ''}`}
Expand All @@ -28,7 +30,7 @@ function ProgressBar({
<div
className={`h-full rounded-md transition-all duration-300 ${fillColor}`}
style={{
width: `${percentage}%`,
width: `${limitedPercentage}%`,
}}
/>
</div>
Expand Down
Loading