-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
[Autocomplete] Impossible to set aria-label on html input of TextField #42627
Comments
This looks like a duplicate of another support question we had on the autocomplete. |
@KingWarin This should work! Here's a demo: https://stackblitz.com/edit/mcve-react-material-ui-npgl9s?file=src%2FApp.tsx // https://github.com/mui/material-ui/issues/42627
import * as React from 'react';
import { Autocomplete, TextField } from '@mui/material';
export default function Playground() {
return (
<Autocomplete
disablePortal
options={OPTIONS}
sx={{ width: 300 }}
renderInput={(params) => (
<TextField
{...params}
inputProps={{
...params.inputProps,
'aria-label': 'foo',
}}
/>
)}
/>
);
}
const OPTIONS = [
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
];
I can't reproduce this, see the demo above! <Autocomplete
renderInput={(params) => (
<TextField
{...params}
InputProps={{
inputProps: {
...params.inputProps,
"aria-label": "foo",
},
}}
/>
)}
/> |
@mj12albert the nesting of Just took a look at your demo. In trying to find a valid combination I didn't add the Thank you very much for the reply. |
Steps to reproduce
Link to live example: Codesandbox
Steps:
Current behavior
When
aria-label
is set:<TextField aria-label="foo" />
), it's onMuiFormControl-Root
, not the<input>
.InputProps
of TextField component (<TextField {...params} InputProps={{ "aria-label": "foo" }} />
), its onMuiInputBase-Root
, not the<input>
.inputProps
of TextField component (<TextField {...params} inputProps={{ "aria-label": "foo" }} />
), it is correctly set on the<input>
but the whole component breaks and produces an error when it is focusedExpected behavior
One of all the possible combinations should yield a functioning Autocomplete with the given aria-label set to the
<input>
Context
I'm creating a form where there is some text explaining what the Autocomplete is used for that is too long to be set as label directly.
Would be glad to give this element an ID and use it on
aria-labelledby
, but this is also impossible to set without breaking the component.Setting a shorter label on the field while having the text before would be redundant and unnecessary.
Your environment
npx @mui/envinfo
Search keywords: accessibility aria-label TextField Autocomplete
The text was updated successfully, but these errors were encountered: