Coder Social home page Coder Social logo

Comments (3)

oliviertassinari avatar oliviertassinari commented on June 30, 2024

This looks like a duplicate of another support question we had on the autocomplete.

from material-ui.

mj12albert avatar mj12albert commented on June 30, 2024

in inputProps of TextField component (<TextField {...params} inputProps={{ "aria-label": "foo" }} />)

@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,
  },
];

it is correctly set on the but the whole component breaks and produces an error when it is focused

I can't reproduce this, see the demo above!
By the way, I also noticed that in some places in your sandbox inputProps is incorrectly nested inside InputProps:

 <Autocomplete
    renderInput={(params) => (
        <TextField
            {...params}
            InputProps={{
              inputProps: {
                ...params.inputProps,
                "aria-label": "foo",
              },
            }}
          />
        )}
      />

from material-ui.

KingWarin avatar KingWarin commented on June 30, 2024

@mj12albert the nesting of inputProps inside InputProps was me trying all possible combinations I (with the help of intellisense) could think of...

Just took a look at your demo. In trying to find a valid combination I didn't add the ...params.inputProps inside the inputProps (as seen in the commented component of my codesandbox) which in led to having the aria-label on the resulting input, but everything else breaking, as the default functions where missing.
So you're absolutely right and after adding the spread it works.

Thank you very much for the reply.

from material-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.