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

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

it('has ARIA attributes for accessibility', () => {
cy.mount(
<Wrapper>
<ProgressBar {...getProps()} />
</Wrapper>
);

cy.findByRole('progressbar')
.should('have.attr', 'aria-valuemin', '0')
.should('have.attr', 'aria-valuemax', '1')
.should('not.have.attr', 'aria-valuenow');
});

it('has aria-valuenow for controlled progress bar', () => {
cy.mount(
<Wrapper>
<ProgressBar {...getProps()} controlledProgress progress={0.5} />
</Wrapper>
);

cy.findByRole('progressbar')
.should('have.attr', 'aria-valuemin', '0')
.should('have.attr', 'aria-valuemax', '1')
.should('have.attr', 'aria-valuenow', '0.5');
});

it('clamps aria-valuenow between 0 and 1', () => {
cy.mount(
<Wrapper>
<ProgressBar {...getProps()} controlledProgress progress={1.5} />
</Wrapper>
);

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

cy.mount(
<Wrapper>
<ProgressBar {...getProps()} controlledProgress progress={-0.5} />
</Wrapper>
);

cy.findByRole('progressbar').should('have.attr', 'aria-valuenow', '0');
});
});
17 changes: 16 additions & 1 deletion src/components/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,21 @@ export function ProgressBar({
}
};

// TODO: add aria-valuenow, aria-valuemax, aria-valuemin
// ARIA attributes for progress bar accessibility
// Only provide aria-valuenow for controlled progress bars where we know the exact value
// For animated progress bars, we omit aria-valuenow as the value changes continuously
const ariaProps: {
'aria-valuemin': number;
'aria-valuemax': number;
'aria-valuenow'?: number;
} = {
'aria-valuemin': 0,
'aria-valuemax': 1
};

if (controlledProgress && typeof progress === 'number') {
ariaProps['aria-valuenow'] = Math.max(0, Math.min(1, progress));
}

return (
<div className={`${Default.CSS_NAMESPACE}__progress-bar--wrp`} data-hidden={isHidden}>
Expand All @@ -125,6 +139,7 @@ export function ProgressBar({
aria-label="notification timer"
className={classNames}
style={style}
{...ariaProps}
{...animationEvent}
/>
</div>
Expand Down