Skip to content

Commit

Permalink
YKI(Frontend): Improve stepper accessibility [deploy]
Browse files Browse the repository at this point in the history
  • Loading branch information
lket committed Jan 19, 2024
1 parent 30a12e0 commit e3ee078
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
3 changes: 3 additions & 0 deletions frontend/packages/yki/public/i18n/fi-FI/public.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@
"stepper": {
"active": "Aktiivinen",
"completed": "Suoritettu",
"label": "Ilmoittautumisen vaiheet.",
"paymentAborted": "Maksu keskeytyi",
"phase": "Vaihe",
"currentStep": "Nykyinen vaihe",
"nextStep": "Seuraava vaihe",
"step": {
"Done": "Valmis",
"Identify": "Tunnistaudu",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Step, StepLabel, Stepper } from '@mui/material';
import { visuallyHidden } from '@mui/utils';
import { useSearchParams } from 'react-router-dom';
import { CircularStepper, H2, Text } from 'shared/components';
import { CircularStepper, Text } from 'shared/components';
import { APIResponseStatus, Color } from 'shared/enums';
import { useWindowProperties } from 'shared/hooks';

Expand Down Expand Up @@ -71,39 +72,57 @@ export const PublicRegistrationStepper = () => {
? PublicRegistrationFormStep.Payment
: Math.min(activeStep, doneStepNumber);

const currentStep = `${t('currentStep')}: ${getDescription(stepValue)}.`;
const nextStep =
stepValue + 1 <= doneStepNumber
? `${t('nextStep')}: ${getDescription(stepValue + 1)}.`
: '';

const mobileStepValue = stepValue * (100 / doneStepNumber);
const mobilePhaseText = `${stepValue}/${doneStepNumber}`;
const mobileAriaLabel = `${t('phase')} ${mobilePhaseText}: ${getDescription(
stepValue
)}`;
const mobileAriaLabel = `${t('phase')} ${mobilePhaseText}.
${currentStep}
${nextStep}`;

if (isPhone) {
return (
<div className="columns gapped-xxl public-registration__grid__circular-stepper-container">
<CircularStepper
value={mobileStepValue}
ariaLabel={mobileAriaLabel}
phaseText={mobilePhaseText}
color={isError ? Color.Error : Color.Secondary}
size={90}
/>
<div className="rows">
<H2>{getDescription(stepValue)}</H2>
{!isError && <Text>{getNextInformation(stepValue)}</Text>}
<div
className="columns gapped-xxl public-registration__grid__circular-stepper-container"
aria-label={t('label')}
role="group"
>
<div aria-hidden={true}>
<CircularStepper
value={mobileStepValue}
ariaLabel={mobileAriaLabel}
phaseText={mobilePhaseText}
color={isError ? Color.Error : Color.Secondary}
size={90}
/>
<div className="rows">
<div>{getDescription(stepValue)}</div>
{!isError && <Text>{getNextInformation(stepValue)}</Text>}
</div>
</div>
<Text sx={visuallyHidden}>{mobileAriaLabel}</Text>
</div>
);
} else {
// eslint-disable-next-line no-console
if (!getStepAriaLabel(1)) console.log('ei');

return (
<Stepper
className="public-registration__grid__stepper"
aria-label={t('label')}
activeStep={stepValue - 1}
role="group"
>
{stepNumbers.map((i) => (
<Step key={i}>
<StepLabel
aria-label={getStepAriaLabel(i)}
error={isError && stepValue === i}
aria-current={stepValue === i && 'step'}
className={
stepValue === i && isError
? 'public-registration__grid__stepper__step-error'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ class PublicRegistrationPage {
elements = {
filterByLanguage: () =>
cy.findByRole('combobox', { name: /Valitse kieli/ }),
filterByLevel: () =>
cy.findByRole('combobox', { name: /Valitse taso/ }),
filterByLevel: () => cy.findByRole('combobox', { name: /Valitse taso/ }),
resultBox: () =>
cy.findByTestId('public-registration-page__grid-container__result-box'),
showOnlyIfAvailablePlaces: () =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dayjs from 'dayjs';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import renderer from 'react-test-renderer';
Expand Down

0 comments on commit e3ee078

Please sign in to comment.