Skip to content

Commit

Permalink
Add aria-labelled by to dropdowns (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
aurorascharff authored Dec 14, 2023
1 parent 30c4bb0 commit 4aadd16
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miljodirektoratet/md-react",
"version": "1.0.36",
"version": "1.0.37",
"description": "React-komponenter for Miljødirektoratet",
"author": "Miljødirektoratet",
"main": "./dist/index.js",
Expand Down
13 changes: 11 additions & 2 deletions packages/react/src/formElements/MdAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ const MdAutocomplete = React.forwardRef<HTMLInputElement, MdAutocompleteProps>(
return (
<div className={classNames}>
<div className="md-autocomplete__label">
{label && label !== '' && <label htmlFor={`md-autocomplete_${uuid}`}>{label}</label>}
{label && label !== '' && (
<label id={`md-autocomplete_label_${uuid}`} htmlFor={`md-autocomplete_${uuid}`}>
{label}
</label>
)}
{helpText && helpText !== '' && (
<div className="md-autocomplete__help-button">
<MdHelpButton
Expand Down Expand Up @@ -192,7 +196,12 @@ const MdAutocomplete = React.forwardRef<HTMLInputElement, MdAutocompleteProps>(
</div>

{options && options.length > 0 && (
<div role="listbox" id={'md-autocomplete__dropdown_${uuid}'} className="md-autocomplete__dropdown">
<div
aria-labelledby={`md-autocomplete_label_${uuid}`}
role="listbox"
id={'md-autocomplete__dropdown_${uuid}'}
className="md-autocomplete__dropdown"
>
{(autocompleteValue ? results : defaultOptions ? defaultOptions : options ? options : []).map(option => {
return (
<button
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/formElements/MdMultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ const MdMultiSelect: React.FunctionComponent<MdMultiSelectProps> = ({
</button>

{options && options.length > 0 && (
<div role="listbox" id={'md-multiselect_dropdown_${uuid}'} className={dropDownClassNames}>
<div
aria-labelledby={`md-multiselect_label_${uuid}`}
role="listbox"
id={'md-multiselect_dropdown_${uuid}'}
className={dropDownClassNames}
>
{options.map(option => {
return (
<div key={`checkbox_key_${uuid}_${option.value}`} className={optionClass(option)}>
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/formElements/MdSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ const MdSelect = React.forwardRef<HTMLButtonElement, MdSelectProps>(
</button>

{options && options.length > 0 && (
<div role="listbox" className="md-select__dropdown" id={'md-select_dropdown_${uuid}'}>
<div
aria-labelledby={`md-select_label_${uuid}`}
role="listbox"
className="md-select__dropdown"
id={'md-select_dropdown_${uuid}'}
>
{options.map(option => {
return (
<button
Expand Down

0 comments on commit 4aadd16

Please sign in to comment.