材质用户界面-单击搜索图标时,未单击搜索栏中的文本字段

时间:2020-09-25 17:58:56

标签: javascript reactjs material-ui

要在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并对此进行处理。还是有一种更简单的方法?

enter image description here

0 个答案:

没有答案