Material-UI: Как показать значок поиска в поле ввода в реагировать? - PullRequest
0 голосов
/ 03 марта 2019

Я использую Материал UI .Я хочу показать search icon в поле ввода, как показано на изображении enter image description here

Я использую этот API

Здесь - это мой код

Я могу показать TextField, но не могу добавить значок поиска.Не могли бы вы добавить, как добавить?

 <TextField id="standard-bare" defaultValue="Bare" margin="normal" />

Ответы [ 2 ]

0 голосов
/ 03 марта 2019

Вам просто нужно импортировать inputAdornment

import InputAdornment from '@material-ui/core/InputAdornment';

и добавить InputProps в textField следующим образом

InputProps={{
  endAdornment: (
    <InputAdornment position="start">
      <SearchIcon />
    </InputAdornment>
   )
  }}

plz найдите приложенный img для демонстрации нужного вамрешение.

enter image description here

0 голосов
/ 03 марта 2019

Вам нужно использовать Входные украшения .

Например:

// imports
import IconButton from "@material-ui/core/IconButton";
import InputAdornment from "@material-ui/core/InputAdornment";
import SearchIcon from "@material-ui/icons/Search";

// render

<TextField
  label="With normal TextField"
  InputProps={{
    endAdornment: (
      <InputAdornment>
        <IconButton>
          <SearchIcon />
        </IconButton>
      </InputAdornment>
    )
  }}
/>

Вот демоверсия:

const {
  TextField,
  InputAdornment,
  IconButton,
  SearchIcon,
  Icon
} = window['material-ui'];

class App extends React.Component {
  render() {
    return (
      <TextField
        label="With normal TextField"
        InputProps={{
          endAdornment: (
            <InputAdornment>
              <IconButton>
                <Icon>search</Icon>
              </IconButton>
            </InputAdornment>
          )
        }}
      />
    );
  }
}

ReactDOM.render(<App />, document.getElementById('root'));
<script src="https://unpkg.com/react@latest/umd/react.development.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/react-dom@latest/umd/react-dom.development.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/@material-ui/core/umd/material-ui.development.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<div id="root"></div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...