要在TextField
上显示搜索图标,这就是我一直在做的事情:
<TextField
size="small"
id="searchCandidate"
data-testid="searchCandidate"
label={textLabel}
variant="outlined"
fullWidth
onChange={onChange}
onBlur={onBlur}
className={classes.searchBar}
InputLabelProps={{
classes: {
focused: classes.cssFocused
}
}}
InputProps={{
classes: {
root: classes.cssOutlinedInput,
focused: classes.cssFocused,
notchedOutline: classes.notchedOutline
},
endAdornment: inputAdornment
}}
/>
和
const inputAdornment = showSearchIcon ? (
<InputAdornment>
<IconButton style={{padding: 0}} aria-label={textLabel}>
<SearchIcon data-testid="search_message" />
</IconButton>
</InputAdornment>
) : null;
由于inputAdornment
,搜索图标出现在文本字段中。但是,如果我单击该图标,则不会单击输入。我可能应该向onclick
提供一个IconButton
并对此进行处理。还是有一种更简单的方法?