我一直在使用 Material UI 来构建 React Web 应用程序。我想使用 InputBase 接收文本并在按“Enter”键时执行操作。我有 onChange 事件正常工作来更新输入,但我似乎无法弄清楚如何进行 onSubmit 操作。
\n\n我尝试过将组件嵌套在表单中,但尚未使其工作。它不仅不执行操作,而且还刷新页面。我发现的唯一有一点帮助的就是这个,但我无法理解它。
\n\ninputBase API 似乎没有相应的功能。有什么建议么?提前致谢!
\n\n这是我的代码:
\n\nimport { fade, makeStyles } from \'@material-ui/core/styles\';\nimport AppBar from \'@material-ui/core/AppBar\';\nimport Toolbar from \'@material-ui/core/Toolbar\';\nimport Typography from \'@material-ui/core/Typography\';\nimport InputBase from \'@material-ui/core/InputBase\';\nimport SearchIcon from \'@material-ui/icons/Search\';\n\nconst useStyles = makeStyles((theme) => ({\n grow: {\n flexGrow: 1,\n },\n title: {\n display: \'none\',\n [theme.breakpoints.up(\'sm\')]: {\n display: \'block\',\n },\n },\n search: {\n position: \'relative\',\n borderRadius: theme.shape.borderRadius,\n backgroundColor: fade(theme.palette.common.white, 0.15),\n \'&:hover\': {\n backgroundColor: fade(theme.palette.common.white, 0.25),\n …Run Code Online (Sandbox Code Playgroud)