我正在使用 AutoComplete(MUI) 创建国家/地区选择器,但收到以下错误消息。 警告:在渲染不同的组件(`
我正在开发一个 React/Typescript 项目。我有一个 Autocomplete 元素,其选项是一系列包含 {label、value 和 endOfDay} 的对象。我有选项标签显示...
我需要在自动完成列表框中给出自定义滚动样式。 我尝试并研究了它,但没有一个起作用。 我最后的代码 我需要在自动完成列表框中给出自定义滚动样式。 我尝试并研究了它,但没有一个起作用。 我最后的代码 <Autocomplete fullWidth popupIcon={<KeyboardArrowDownIcon />} id="combo-box-demo" options={allTableData} noOptionsText={"Məhsul tapılmadı"} getOptionLabel={(option) => option.name ?? option} ListboxProps={{ style: { maxHeight: "200px", "&::-webkit-scrollbar": { width: "20px", }, }, }} 是的,您可以将自定义 className 传递给 ListboxProps 组件的 Autocomplete,如下所示: ListboxProps={{ className: "myCustomList" }} 然后将滚动条相关的CSS添加到此类中,如下所示: .myCustomList::-webkit-scrollbar { width: 12px; background-color: #5f6f9c; } .myCustomList::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3); background-color: #d62929; } 您可以查看此沙箱,了解此解决方案的实时工作示例。 而不是在 style 属性中添加样式;在 ListBoxProps 中添加 'sx' 属性中的样式。这对我有用。 ListboxProps={{ sx: { maxHeight: 300, // Adjust this value as per your requirement '&::-webkit-scrollbar': { width: '8px' }, '&::-webkit-scrollbar-track': { backgroundColor: theme.palette.background.default }, '&::-webkit-scrollbar-thumb': { backgroundColor: theme.palette.primary.main, borderRadius: '10px', border: `2px solid ${theme.palette.background.paper}` }, '&::-webkit-scrollbar-thumb:hover': { backgroundColor: theme.palette.primary.dark } } }}
react-testing-library:无法关闭 MUI Select 的下拉菜单
我有一个 SelectExample.js 从“react”导入 React, { useState }; 从“@mui/material”导入{InputLabel、MenuItem、FormControl、Select、Typography };> 导出默认fu...
@types/material-ui 和官方的@mui/types 包有什么区别?
npm 包:@types/material-ui 和 @mui/types 我知道前者受到 Definely Typed 社区的支持,但如果存在官方类型包,为什么它首先存在呢?我已经
无法在 MUI DatePicker 中使用复选图标可视化徽章
我在这个项目中使用 MUI Date Picker 和 React.js。 我遇到的问题是,我无法可视化应根据当前突出显示的日期呈现为徽章的 checkIcon
我正在使用 MUI X Data Grid v5 和 Tanstack React Query v4 我正在尝试在我的 Datagrid 组件上使用分页,当页面最初加载时,它会按预期正常获取并加载网格。
Mat-autocomplete 和 mat-option 事件在过滤后分页速度太慢?
使用我设法从API中找到的任何类型的事件进行选择和自动完成最终都会导致MatPaginator“落后一步”,例如而过滤后的数据应该只有 200 个...
我有一个使用 MUI 构建的 React 应用程序的自定义 Moviecard 组件,对于我使用的每个 Typography 组件,它也有一个相当烦人且粘性的下划线。我想摆脱它,但...
我为 MUI 菜单中的每个 MenuItem 创建了一个复选框。用户可以一次选择多个菜单项。 有没有办法获取所选菜单项的值? 因为如果我把 event.ta...
我想在将新行添加到表格后在其旁边添加一个标签。我找到了 MUI 徽章。我怎样才能更改号码并将其替换为“New”一词? 像这样的东西 输入图片描述
为什么我会在 React/TypeScript/MUI 对话框中看到这种奇怪的行为?
我在 React/TypeScript/MUI 应用程序的流程中出现了一个对话框,其中显示了几个按钮。当您选择每个按钮时,对话框功能会将按钮的值添加到状态...
在 MUI Data Grid v6 中更新另一个单元格时,如何在编辑模式下更新一个单元格?
我正在使用 MUI Data Grid v6 组件并利用其内置的 CRUD 编辑功能。我有多个列,所有列都可以编辑。在我的“类别&...”列中选择新值后
如何在 React 组件的 Jest 测试中模拟 MUI5 Pro 许可证密钥
我目前正在将 MUI v5 Pro 组件集成到我的 React 库中,然后将这些库组件导入到我的主机应用程序中。我已经在两个 Libra 的 .env 文件中设置了 MUI 许可证密钥...
如何添加操作:单击图表并从 MUI X 图表 BarChart 中的图表获取数据?
我有一个显示数据的图表,我希望当我单击某个列时我可以获得该列的值 并将该值显示到控制台屏幕。 数据图 我使用 MUI X 图表 BarChart 以及如何...
如何在下一个js应用程序路由器中实现mui风格的组件而不使用“使用客户端”
我想在nextjs 14中使用mui风格的组件,但在每个页面上我必须写“使用客户端”,我想使用nextjs ssr功能但它强迫我进行csr,如何实现它?请
如何将 mui stepper connect 变成进度条?每个步骤也有步骤内容
我希望 mui 步进器连接器的行为就像进度指示器。 每个步骤也有步骤内容部分。步骤内容和连接器是两个单独的 div,我无法对其进行样式设置。任何人都可以...
MUI-table:mui 表组件中交替行的不同颜色不起作用
为备用表格行添加不同的颜色不起作用 函数行(道具){ const { 行 } = 道具; const StyledTableRow = styled(TableRow)(({ 主题 }) => ({ '&:第 n 个类型...
`我的 React 应用程序运行良好,但升级到 React 18、mui v5 和 redux v5 后,它没有渲染任何内容。 在终端中,我得到: webpack 编译成功 但在 chrome 控制台中...
我需要找到 SELECT DATE 标签的 localeText 属性。我尝试了几个 localeText 道具。最后的解决方案是用 CSS 删除标签。但如果我找到道具,我会让标签变得动态......
所以我有一张垫子桌 所以我有一张垫子桌 <mat-table class="table" cdkDropList cdkDropListOrientation="horizontal" (cdkDropListDropped)="tableDrop($event)" [dataSource]="tableDataSource"> <ng-container *ngFor="let column of columns; let i = index" [matColumnDef]="column.name"> <mat-header-cell *matHeaderCellDef cdkDrag dkDragLockAxis="x" cdkDragBoundary="mat-header-row"> {{ column.title }} </mat-header-cell> <mat-cell *matCellDef="let element"> {{ element[column.name] }} </mat-cell> </ng-container> <mat-header-row class="tableHeader" *matHeaderRowDef="tableDisplayedColumns" #tableHeaderRow> </mat-header-row> <mat-row class="tableRow" *matRowDef="let row; columns: tableDisplayedColumns;" [class.selected-row]="tableSelectedRows.has(row)" (click)="selectUnselectRow(row)"> </mat-row> </mat-table> 但我需要在表标题下为相应的行过滤器添加一行。我尝试在标题和实际行声明之间添加 <mat-row> ,但是由于过滤器是不同的输入(例如数字、自动完成选择和多选),我无法 *ngFor 它们(而且我不是当然我是否能够) 编辑:忘记发布过滤器 HTML <div class="filterGroup"> <mat-form-field class="filterField"> <input matInput type="number" (keydown)="updateManualPage(1)" placeholder="Filter za param1" formControlName="filterParam1"> </mat-form-field> <mat-form-field class="filterField"> <input matInput (keydown)="updateManualPage(1)" placeholder="Filter za param2" formControlName="filterParam2" [matAutocomplete]="autoSingleSelect"> <mat-autocomplete #autoSingleSelect="matAutocomplete" class="filterSelect" panelClass="filterSelect"> <mat-option *ngFor="let option of dropdownSingleFilteredOptions | async" [value]="option.param2"> {{option.param2}} </mat-option> </mat-autocomplete> </mat-form-field> <mat-form-field class="filterField"> <mat-select class="filterMultiselect" placeholder="Filter za param3" formControlName="filterParam3" multiple panelClass="filterMultiselect"> <mat-option *ngFor="let option of tableDataSource.data" [value]="option.param3"> {{option.param3}} </mat-option> </mat-select> </mat-form-field> </div> 以及相关组件.ts tableDisplayedColumns: string[] = ['param1', 'param2', 'param3']; columns: any[] = [ { name: 'param1', title: 'Param1' }, { name: 'param2', title: 'Param2' }, { name: 'param3', title: 'Param3' } ]; 为了解决这个问题,我设法通过删除 *ngFor 并手动放入过滤器来做到这一点。 <mat-table class="table" cdkDropList cdkDropListOrientation="horizontal" (cdkDropListDropped)="tableDrop($event)" [dataSource]="tableDataSource"> <ng-container matColumnDef="param1"> <mat-header-cell *matHeaderCellDef cdkDrag cdkDragLockAxis="x" cdkDragBoundary="mat-header-row" [cdkDragStartDelay]="100"> Param1 <mat-form-field class="filterField"> <input matInput type="number" (keydown)="updateManualPage(1)" placeholder="Filter" formControlName="filterParam1"> </mat-form-field> </mat-header-cell> <mat-cell *matCellDef="let data"> <span>{{data.param1}}</span> </mat-cell> </ng-container> <ng-container matColumnDef="param2"> <mat-header-cell *matHeaderCellDef cdkDrag cdkDragLockAxis="x" cdkDragBoundary="mat-header-row" [cdkDragStartDelay]="100"> Param2 <mat-form-field class="filterField"> <input matInput (keydown)="updateManualPage(1)" placeholder="Filter" formControlName="filterParam2" [matAutocomplete]="autoSingleSelect"> <mat-autocomplete #autoSingleSelect="matAutocomplete" class="filterSelect" panelClass="filterSelect"> <mat-option *ngFor="let option of dropdownSingleFilteredOptions | async" [value]="option.param2"> {{option.param2}} </mat-option> </mat-autocomplete> </mat-form-field> </mat-header-cell> <mat-cell *matCellDef="let data"> <span>{{data.param2}}</span> </mat-cell> </ng-container> <ng-container matColumnDef="param3"> <mat-header-cell *matHeaderCellDef cdkDrag cdkDragLockAxis="x" cdkDragBoundary="mat-header-row" [cdkDragStartDelay]="100"> Param3 <mat-form-field class="filterField"> <mat-select class="filterMultiselect" placeholder="Filter" formControlName="filterParam3" multiple panelClass="filterMultiselect"> <mat-option *ngFor="let option of tableDataSource.data" [value]="option.param3"> {{option.param3}} </mat-option> </mat-select> </mat-form-field> </mat-header-cell> <mat-cell *matCellDef="let data"> <span>{{data.param3}}</span> </mat-cell> </ng-container> <mat-header-row class="tableHeader" *matHeaderRowDef="tableDisplayedColumns" #tableHeaderRow> </mat-header-row> <mat-row class="tableRow" *matRowDef="let row; columns: tableDisplayedColumns;" [class.selected-row]="tableSelectedRows.has(row)" (click)="selectUnselectRow(row)"> </mat-row> </mat-table>
在我的应用程序中,我需要渲染一个没有抽屉的登录页面,并渲染抽屉内的其余页面。所以我创建了 Home.jsx 文件,其中包含抽屉并将我的路线放在我的里面......
使用自定义日期字段(@mui/x-date-pickers/DatePicker)进行编辑后,行为是该字段粘贴在屏幕上。所有自定义输入字段都会发生这种情况。如果我使用地铁 '...
Material Ui DatePicker 使用键盘输入时总是得到无效日期
我试图将 mui-x/datepicker 与佛教年份一起使用,使用 dayjs 作为适配器,当我使用日历弹出窗口作为输入时,它工作正常,但是当我使用键盘输入日期并更改
为什么表单属性不能像 html 按钮字段那样在 MUI 按钮上工作?
我需要使用带有zod验证的react hook表单提交表单。但在我的情况下,提交按钮位于表单标记之外。所以我使用了id形式的方法。 (请调整任何其他方法...
Material UI OutlinedInput 标签不可见
我们正在使用 Material UI 中的 OutlinedInput,但文本标签不会呈现。如何解决这个问题? 从 '@material-ui/core' 导入 { Grid, OutlinedInput }; 我们正在使用 Material UI 中的 OutlinedInput,但文本标签不会渲染。如何解决这个问题? import { Grid, OutlinedInput } from '@material-ui/core'; <Grid container> <Grid item xs={12}> <OutlinedInput label="invisible label" placeholder="HELLO, STACKOVERFLOW!" value={value} onChange={(e) => handleValueChange(e.target.value)} fullWidth /> </Grid> </Grid> 渲染的是一个空白区域(左上角),而不是预期的“不可见标签”文本: 就像 @Daniel L 提到的,你必须在 InputLabel 组件中使用 FormControl 组件,但除了他的答案之外 - 我还必须在我的 label 组件上添加 OutlinedInput 属性,以便轮廓输入不会与我的标签重叠。 不带label属性的代码: <FormControl sx={{ m: 1, width: '25ch' }} variant="outlined"> <InputLabel htmlFor='display-name'>Display Name</InputLabel> <OutlinedInput id="display-name" value={displayName} onChange={(e) => handleInputChange(e)} aria-describedby="base-name-helper-text" inputProps={{ 'aria-label': 'weight', }} /> </FormControl> 带有标签属性的代码: <FormControl sx={{ m: 1, width: '25ch' }} variant="outlined"> <InputLabel htmlFor='display-name'>Display Name</InputLabel> <OutlinedInput id="display-name" value={displayName} label='Display Name' onChange={(e) => handleInputChange(e)} aria-describedby="base-name-helper-text" inputProps={{ 'aria-label': 'weight', }} /> </FormControl> 对此问题的快速回答基本上是将组件包装在 FormControl 下,并在 InputLabel 组件顶部添加 OutlinedInput。 根据您的代码,它应该如下所示: <Grid container> <Grid item xs={12}> <FormControl> <InputLabel htmlFor="outlined-adornment">Some text</InputLabel> <OutlinedInput id="outlined-adornment" placeholder="HELLO, STACKOVERFLOW!" value={value} onChange={(e) => handleValueChange(e.target.value)} fullWidth /> </FormControl> </Grid> </Grid> 我认为这个组件不适合单独使用。在 MUI 文档中,它主要用作其他组件的增强,例如 TextField <TextField id="outlined-basic" label="Outlined" variant="outlined" /> 如果您检查开发工具中的样式,看起来 CSS 属性 visibility: hidden 导致了此问题。事实上,如果您删除该样式,您将看到该标签有效。 但是,如果您已经使用此组件构建了大部分应用程序并且需要显示该标签,只需使用 MUI 的样式解决方案(例如 makeStyles)覆盖它即可。另外,使用 notched prop 为其分配空间 const useStyles = makeStyles({ customInputLabel: { "& legend": { visibility: "visible" } } }); export default function App() { const classes = useStyles(); return ( <div className="App"> <Grid container> <Grid item xs={12}> <OutlinedInput classes={{ notchedOutline: classes.customInputLabel }} label="visible label" placeholder="HELLO, STACKOVERFLOW!" fullWidth notched /> </Grid> </Grid> </div> ); } 我遇到了同样的问题,我将 OutlinedInput 包装到 FormControl 元素中,并附加 InputLabe 组件作为标签,这解决了我的问题。 要点: 方向:“ltr”确保标签文本对于从左到右的语言正确对齐。 &.MuiFormLabel-root:not(.MuiFormLabel-filled):not(.Mui-focused) 等规则可让您定位不同状态下的标签。 确保应用 ThemeProvider 来包装您的应用程序或特定组件以应用这些样式。 const const theme = createTheme({ MuiInputLabel:{ defaultProps:{}, styleOverrides:{ root:{ direction:"ltr", width:"100%", textAlign:"end", fontSize:20, "&.MuiFormLabel-root:not(.MuiFormLabel-filled):not(.Muifocused)":{color:'pink'}, "&.Mui-focused":{left:30,top:-10}, "&.MuiFormLabel-filled:not(.Mui-focused)":{left:30, top:-6} }, }, },
我有一个按钮可以下载带有文件名的文件。为此,我写了这样的内容: 我有一个按钮可以下载带有文件名的文件。为此,我写了这个: <Button color='primary' href=`/apiproxy/objects/${id}/subobjects` LinkComponent={React.forwardRef((props, ref) => <Link {...props} type='text/csv' download={`object_${id}_subobjects.csv`} ref={ref} />)} /> 生成的元素看起来与我的其他没有 href 属性的按钮相同(也带有 color='primary'),但悬停时其文本颜色更改为蓝色,与其他按钮不同,它保持白色。 如何使其样式与其他按钮相同?我可以将 &:hover 文本颜色指定为白色,但是当主题更改其他按钮的文本颜色时,这会中断。 有没有办法更改链接组件,使其样式与其他按钮相同,或者如果没有,按钮在调色板中使用什么作为悬停文本颜色,以便我可以将其设置为该颜色? 我认为您可以使用 styledComponent 作为链接组件。就像下面... const theme = useTheme(); const StyledLink = styled(Link)(({ theme, color = "primary" }) => ({ ":hover": { color: theme.palette.secondary.main, }, })); <Button color="primary" href="/apiproxy/objects/1/subobjects" LinkComponent={React.forwardRef((props, ref) => ( <StyledLink {...props} type="text/csv" download={"object_1_subobjects.csv"} ref={ref} theme={theme} /> ))} /> 您可以在 theme.js 文件中的调色板中设置悬停颜色,并使用该颜色,如 theme.palette.${hoverColor} 请检查此测试组件。 https://codesandbox.io/p/sandbox/mui-28251-28335-forked-j2x8cd?file=%2Fsrc%2FApp.js 也许您可以让按钮将它们重定向到可以下载文件的 MediaFire: <a href="link-to-media"><button class="buttonClass">Download</button></a> 然后你可以将buttonClass修改为你喜欢的任何内容。