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

feat(progress-indicator): adds hidden span to announce state of completion #5125

Merged
merged 10 commits into from
Jan 24, 2020
2 changes: 2 additions & 0 deletions packages/components/docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -20453,6 +20453,7 @@ Progress indicator styles
margin-left: $carbon--spacing-06;
margin-top: rem(28px);
color: $text-01;
text-align: start;
}

//CURRENT STYLING
Expand Down Expand Up @@ -20489,6 +20490,7 @@ Progress indicator styles

//interactive button
.#{$prefix}--progress-step-button {
@include button-reset();
display: flex;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
margin-left: $carbon--spacing-06;
margin-top: rem(28px);
color: $text-01;
text-align: start;
}

//CURRENT STYLING
Expand Down Expand Up @@ -168,6 +169,7 @@

//interactive button
.#{$prefix}--progress-step-button {
@include button-reset();
display: flex;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('ProgressIndicator', () => {
mountedList
.find(ProgressStep)
.at(0)
.find('[role="button"]')
.find('button')
.simulate('click');
expect(mockOnChange).toHaveBeenCalledWith(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,33 @@ import { CheckmarkOutline16, Warning16 } from '@carbon/icons-react';
import { keys, matches } from '../../internal/keyboard';

const { prefix } = settings;

const defaultRenderLabel = props => <p {...props} />;
export const ProgressStep = ({ ...props }) => {
const {
label,
description,
className,
current,
complete,
invalid,
secondaryLabel,
disabled,
onClick,
renderLabel: ProgressStepLabel,
} = props;

const defaultTranslations = {
'carbon.progress-step.complete': 'Complete',
'carbon.progress-step.incomplete': 'Incomplete',
'carbon.progress-step.current': 'Current',
'carbon.progress-step.invalid': 'Invalid',
};

function translateWithId(messageId) {
return defaultTranslations[messageId];
}

export function ProgressStep({
label,
description,
className,
current,
complete,
invalid,
secondaryLabel,
disabled,
onClick,
renderLabel: ProgressStepLabel,
translateWithId: t,
}) {
const classes = classnames({
[`${prefix}--progress-step`]: true,
[`${prefix}--progress-step--current`]: current,
Expand Down Expand Up @@ -70,16 +82,31 @@ export const ProgressStep = ({ ...props }) => {
);
};

let message = t('carbon.progress-step.incomplete');

if (current) {
message = t('carbon.progress-step.current');
}

if (complete) {
message = t('carbon.progress-step.complete');
}

if (invalid) {
message = t('carbon.progress-step.invalid');
}

return (
<li className={classes} aria-disabled={disabled}>
<div
<li className={classes}>
<button
className={classnames(`${prefix}--progress-step-button`, {
[`${prefix}--progress-step-button--unclickable`]: !onClick || current,
})}
role="button"
aria-disabled={disabled}
tabIndex={!current && onClick ? 0 : -1}
onClick={!current ? onClick : undefined}
onKeyDown={handleKeyDown}>
<span className={`${prefix}--assistive-text`}>{message}</span>
<SVGIcon
complete={complete}
current={current}
Expand All @@ -94,10 +121,10 @@ export const ProgressStep = ({ ...props }) => {
<p className={`${prefix}--progress-optional`}>{secondaryLabel}</p>
) : null}
<span className={`${prefix}--progress-line`} />
</div>
</button>
</li>
);
};
}

ProgressStep.propTypes = {
/**
Expand Down Expand Up @@ -165,10 +192,17 @@ ProgressStep.propTypes = {
* A callback called if the step is clicked or the enter key is pressed
*/
onClick: PropTypes.func,

/**
* Optional method that takes in a message id and returns an
* internationalized string.
*/
translateWithId: PropTypes.func,
};

ProgressStep.defaultProps = {
renderLabel: defaultRenderLabel,
translateWithId,
};

export class ProgressIndicator extends Component {
Expand Down