Select, MultiSelect, Autocomplete and TagsInput label their listbox by a label id that isn't rendered
Dependencies check up
- I have verified that I use latest version of all @mantine/* packages
What version of @mantine/* packages do you have in package.json?
9.6.3
What package has an issue?
@mantine/core
What framework do you use?
Other, I will specify in the bug description (a React component library, react-jsonschema-form)
In which browsers you can reproduce the issue?
Not applicable – issue is not related to the browser
Describe the bug
Select, MultiSelect, Autocomplete and TagsInput compute the dropdown listbox's aria-labelledby from the label prop alone:
labelId: others.label ? `${_id}-label` : undefined,But InputWrapper only renders the label when inputWrapperOrder includes 'label', and gives it labelProps.id when one is set. So the listbox references an id that doesn't exist:
- when
inputWrapperOrderleaves out'label'(the label is not rendered at all), or - when
labelProps={{ id: 'custom' }}is passed (the label renders ascustom, the listbox still references<id>-label).
This is the same problem #9217 fixed for the InputWrapper context in 9.6.3 (labelId: _label && inputWrapperOrder.includes("label") ? labelId : void 0), but these combobox inputs build their own id instead of using that one.
Reproduction:
import { MantineProvider, Select } from '@mantine/core';
export default function Demo() {
return (
<MantineProvider>
<Select id='fruit' label='Fruit' inputWrapperOrder={['input', 'error']} data={['Apple', 'Banana']} />
<Select id='veg' label='Vegetable' labelProps={{ id: 'veg-title' }} data={['Carrot', 'Pea']} />
</MantineProvider>
);
}The first listbox has aria-labelledby="fruit-label", and no element has that id. The second has aria-labelledby="veg-label" while the label's id is veg-title.
Expected: the listbox is labelled by the label element that is actually rendered, or has no aria-labelledby when none is.
Possible fix
Read the label id from InputWrapperContext (which since 9.6.3 is only set when the label is rendered, and honours labelProps.id) instead of rebuilding it, or apply the same condition:
labelId: others.label && inputWrapperOrder.includes('label') ? labelProps?.id || `${_id}-label` : undefined,The same line exists in Select.tsx, MultiSelect.tsx, Autocomplete.tsx and TagsInput.tsx.
Self-service
- I would be willing to implement a fix for this issue
Source: mantinedev/mantine