简体   繁体   English

Material-ui Autocomplete:指定自定义 CloseIconButton

[英]Material-ui Autucomplete: specifying custom CloseIconButton

folks伙计们

So my issue is simple.所以我的问题很简单。 I want to provide custom closeIconButton.我想提供自定义的 closeIconButton。 And only closeIcon prop is available.并且只有 closeIcon 道具可用。 CloseIcon prop doesn't suffice because I need this custom button to have onClick property. CloseIcon 道具还不够,因为我需要这个自定义按钮具有 onClick 属性。 And if I place onClick on CloseIcon material-ui will warn: Failed prop type: Material-UI: you are providing an onClick event listener to a child of a button element. Firefox will never trigger the event.如果我将 onClick 放在 CloseIcon material-ui 上会警告: Failed prop type: Material-UI: you are providing an onClick event listener to a child of a button element. Firefox will never trigger the event. Failed prop type: Material-UI: you are providing an onClick event listener to a child of a button element. Firefox will never trigger the event.

<Autocomplete
     open={open}
     classes={classes}
     options={practicesList}
     getOptionLabel={get('name')}
     value={curPractice}
     blurOnSelect
     closeIcon={<CloseIcon onClick={() => onChange(null)} />}
     onChange={async (e, option) => {
       if (!option) return

       onChange(option.id)
     }}
     renderInput={params => <TextField {...params} autoFocus={autoFocus} fullWidth label={label} margin="none" />}
     renderOption={(practice, { inputValue }) => {
       const matches = match(practice.name, inputValue)
       const letters = parse(practice.name, matches)

       return (
         <div>
           {letters.map((letter, i) => (
             <span key={i} style={{ fontWeight: letter.highlight ? 700 : 400 }}>
               {letter.text}
             </span>
           ))}
         </div>
       )
     }}
   />

From api docs closeIcon should be just some node.api docs closeIcon应该只是一些节点。 For example:例如:

<CloseIcon fontSize="small" />

Than, you can use onClose prop directly on Autocomplete component to specify some callback.然后,您可以直接在Autocomplete组件上使用onClose来指定一些回调。 Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM