Skip to content

Commit

Permalink
🚸 [#4269] Cleanup and improve a11y
Browse files Browse the repository at this point in the history
Use the existing VariableSelection component to render a
dropdown of available Open Forms variables.

Added an accessible label to the dropdowns in the mapping
tables.
  • Loading branch information
sergei-maertens committed May 8, 2024
1 parent a2c8131 commit f7121f5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {parseExpression} from 'feelin';
import {useFormikContext} from 'formik';
import React, {useContext, useState} from 'react';
import React, {useContext} from 'react';
import {FormattedMessage} from 'react-intl';
import {useAsync} from 'react-use';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DeleteIcon from 'components/admin/DeleteIcon';
import ButtonContainer from 'components/admin/forms/ButtonContainer';
import Field from 'components/admin/forms/Field';
import Select from 'components/admin/forms/Select';
import VariableSelection from 'components/admin/forms/VariableSelection';

const VariableMapping = ({loading, mappingName, formVariables, dmnVariables}) => {
const intl = useIntl();
Expand Down Expand Up @@ -48,11 +49,13 @@ const VariableMapping = ({loading, mappingName, formVariables, dmnVariables}) =>
name={`${mappingName}.${index}.formVariable`}
htmlFor={`${mappingName}.${index}.formVariable`}
>
<Select
<VariableSelection
id={`${mappingName}.${index}.formVariable`}
allowBlank
choices={formVariables}
{...getFieldProps(`${mappingName}.${index}.formVariable`)}
aria-label={intl.formatMessage({
description: 'Accessible label for (form) variable dropdown',
defaultMessage: 'Form variable',
})}
/>
</Field>
</td>
Expand All @@ -67,6 +70,10 @@ const VariableMapping = ({loading, mappingName, formVariables, dmnVariables}) =>
disabled={loading}
choices={dmnVariables}
{...getFieldProps(`${mappingName}.${index}.dmnVariable`)}
aria-label={intl.formatMessage({
description: 'Accessible label for DMN variable dropdown',
defaultMessage: 'DMN variable',
})}
/>
</Field>
</td>
Expand Down
13 changes: 11 additions & 2 deletions src/openforms/js/components/admin/forms/VariableSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ const VariableSelection = ({
onChange,
includeStaticVariables = false,
filter = allowAny,
...props
}) => {
const {formSteps, formVariables, staticVariables} = useContext(FormContext);

let formDefinitionsNames = {};
formSteps.map(step => {
formSteps.forEach(step => {
formDefinitionsNames[step.formDefinition || step._generatedId] = step.internalName || step.name;
});

Expand All @@ -36,7 +37,15 @@ const VariableSelection = ({
/*TODO: This should be a searchable select for when there are a billion variables -> react-select */
}
return (
<Select id={id} name={name} choices={choices} allowBlank onChange={onChange} value={value} />
<Select
id={id}
name={name}
choices={choices}
allowBlank
onChange={onChange}
value={value}
{...props}
/>
);
};

Expand Down

0 comments on commit f7121f5

Please sign in to comment.