Skip to content
Open
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
36 changes: 36 additions & 0 deletions src/components/ProgressBar.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,40 @@ describe('ProgressBar', () => {

cy.findByRole('progressbar').should('have.attr', 'style').and('include', 'scaleX(0.7)');
});

it('should have ARIA attributes when controlled progress is used', () => {
cy.mount(
<Wrapper>
<ProgressBar {...getProps()} controlledProgress progress={0.7} />
</Wrapper>
);

cy.findByRole('progressbar')
.should('have.attr', 'aria-valuenow', '70')
.and('have.attr', 'aria-valuemin', '0')
.and('have.attr', 'aria-valuemax', '100');
});

it('should convert progress values correctly to percentage', () => {
cy.mount(
<Wrapper>
<ProgressBar {...getProps()} controlledProgress progress={0.35} />
</Wrapper>
);

cy.findByRole('progressbar')
.should('have.attr', 'aria-valuenow', '35');
});

it('should handle string progress values', () => {
cy.mount(
<Wrapper>
<ProgressBar {...getProps()} controlledProgress progress="0.85" />
</Wrapper>
);

cy.findByRole('progressbar')
.should('have.attr', 'aria-valuenow', '85');
});

});
13 changes: 11 additions & 2 deletions src/components/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ export function ProgressBar({
}
};

// TODO: add aria-valuenow, aria-valuemax, aria-valuemin
const shouldShowAria = controlledProgress && progress !== undefined;
const progressValue = shouldShowAria ? (typeof progress === 'number' ? progress : parseFloat(progress || '0')) : 0;
const ariaValueNow = Math.min(100, Math.max(0, Math.round(progressValue * 100)));
const ariaValueMin = 0;
const ariaValueMax = 100;

return (
<div className={`${Default.CSS_NAMESPACE}__progress-bar--wrp`} data-hidden={isHidden}>
Expand All @@ -122,7 +126,12 @@ export function ProgressBar({
<div
role="progressbar"
aria-hidden={isHidden ? 'true' : 'false'}
aria-label="notification timer"
aria-label={'Notification progress bar: ' + ariaValueNow + ' percent'}
{...(shouldShowAria && {
'aria-valuenow': ariaValueNow,
'aria-valuemin': ariaValueMin,
'aria-valuemax': ariaValueMax
})}
className={classNames}
style={style}
{...animationEvent}
Expand Down