标签: material-ui

ReactJS + Material-UI:如何在 Material-UI <Table/> 的 <TableRow/> 之间交替颜色?

I currently have a Material-UI's <Table/> ( http://www.material-ui.com/#/components/table ), and would like each row to switch off between color blue and purple. So first one would be blue, then next row would be purple, and so on for any additional row added.

How can I dynamically switch off between two colors for any additional rows added?

render(){

    return(
        <Table
          multiSelectable={true}
        >
          <TableHeader>
            <TableRow>
              <TableHeaderColumn>First Name</TableHeaderColumn>
              <TableHeaderColumn>Last Name</TableHeaderColumn>
              <TableHeaderColumn>Color</TableHeaderColumn>
            </TableRow>
          </TableHeader>
          <TableBody
            displayRowCheckbox={true}
            stripedRows
          >
              <TableRow>
                <TableRowColumn>John</TableRowColumn>
                <TableRowColumn>Smith</TableRowColumn>
                <TableRowColumn>Red</TableRowColumn>
              </TableRow>
              <TableRow> …
Run Code Online (Sandbox Code Playgroud)

html javascript css reactjs material-ui

11
推荐指数
4
解决办法
1万
查看次数

使用 Material-UI 纸垂直对齐

我想在 Material-UI Paper 组件中垂直对齐一些文本。

代码在这里:https : //codesandbox.io/embed/material-demo-fz9wj

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';

const useStyles = makeStyles(theme => ({
  root: {
    padding: theme.spacing(3, 2),
    height: 200,
    verticalAlign: 'middle'
  },
}));

function PaperSheet() {
  const classes = useStyles();

  return (
    <div>
      <Paper className={classes.root}>
        <Typography variant="h5" component="h3">
          This is a sheet of paper.
        </Typography>
        <Typography component="p">
          Paper can be used to build surface or other elements for your application. …
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui

11
推荐指数
2
解决办法
3万
查看次数

使用 @testing-library/react 测试材质 ui 滑块

您好我想测试与材料的UI创建一个Slider组件,但我不能让我的测试通过。我想使用fireEventwith测试值的变化@testing-library/react。我一直在关注这篇文章以正确查询 DOM,但我无法获得正确的 DOM 节点。

提前致谢。

<Slider /> 成分

// @format
// @flow

import * as React from "react";
import styled from "styled-components";
import { Slider as MaterialUISlider } from "@material-ui/core";
import { withStyles, makeStyles } from "@material-ui/core/styles";
import { priceRange } from "../../../domain/Search/PriceRange/priceRange";

const Wrapper = styled.div`
  width: 93%;
  display: inline-block;
  margin-left: 0.5em;
  margin-right: 0.5em;
  margin-bottom: 0.5em;
`;

// ommited code pertaining props and styles for simplicity

function Slider(props: SliderProps) {
  const initialState = …
Run Code Online (Sandbox Code Playgroud)

testing reactjs jestjs material-ui react-testing-library

11
推荐指数
2
解决办法
4453
查看次数

在 Material-ui Autocomplete 组件上设置文本颜色、轮廓和内边距

我们想更改 Material-ui 自动完成组件上的文本颜色、轮廓和填充。

代码如下所示:

              <FormControlLabel
                label="Please enter desired service:"
                labelPlacement="start"
                control={
                  <Autocomplete
                    id="services"
                    options={props.serviceTypes}
                    getOptionLabel={option => option.name}
                    className={classes.inputRoot}
                    style={{ width: 400, paddingLeft: 20 }}
                    renderInput={params => (
                      <TextField
                        {...params}
                        label=""
                        className={classes.inputRoot}
                        variant="outlined"
                        fullWidth
                      />
                    )}
                    onChange={setService}
                  />
                }
              />
Run Code Online (Sandbox Code Playgroud)

我们可以通过这样的代码更改 TextInput 颜色

                        InputProps={{
                          className: classes.inputColor
                        }}
Run Code Online (Sandbox Code Playgroud)

但是以这种方式应用样式会影响 AutoComplete 功能(它失去了自动完成功能并且表现得像一个普通的 TextField)。

我们尝试了许多 style 和 className 选项都无济于事。

感谢任何建议。

reactjs material-ui

11
推荐指数
1
解决办法
2万
查看次数

材质 UI 选择 - 选择尺寸

在使用 Material UI 中的选择时,我正在努力让它们正常工作,使用高度和宽度适当地使用“vh”和“vw”以及使用“vh”的文本大小。

我最终获得了合适的框大小,但由于显然使用“变换”从左上角偏移自身,因此标签文本不再居中。

无论如何,这就是我所拥有的:https : //codesandbox.io/s/material-demo-ujz2g

import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import InputLabel from "@material-ui/core/InputLabel";
import MenuItem from "@material-ui/core/MenuItem";
import FormHelperText from "@material-ui/core/FormHelperText";
import FormControl from "@material-ui/core/FormControl";
import Select from "@material-ui/core/Select";

const useStyles = makeStyles(theme => ({
  formControl: {
    margin: theme.spacing(1),
    width: "20vw"
  },
  selectEmpty: {
    marginTop: theme.spacing(2)
  },
  select: {
    height: "10vh"
  },
  inputLabel: {
    fontSize: "4vh",
    alignSelf: "center"
  }
}));

export default function SimpleSelect() {
  const classes = useStyles();
  const …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs material-ui

11
推荐指数
3
解决办法
1万
查看次数

如何在 TextField 中使用 ref

我原来的代码是这样的:

handleClick() {
  var name = this.refs.name.value;
  var description = this.refs.description.value
}
render () {
return (
  <React.Fragment>
    <input ref='name' placeholder='Enter the name of the item' />
    <input ref='description' placeholder='Enter a description' />
    <Button onClick={this.handleClick.bind(this)}>Submit</Button>
  </React.Fragment>
);}
Run Code Online (Sandbox Code Playgroud)

name并且description可以正确获取输入。但是当我使用<TextField>

<TextField ref='name' placeholder='Enter the name of the item' />
Run Code Online (Sandbox Code Playgroud)

它显示传递的值是null,似乎ref不起作用。谁能帮我解决这个问题?

ref textfield material-ui

11
推荐指数
1
解决办法
2万
查看次数

使用组件实验室 &gt; 自动完成功能在 Material UI 中为 SVG 图标编译错误

当我在浏览器上运行我的项目时出现以下错误:

编译失败:

./node_modules/@material-ui/lab/esm/internal/svg-icons/Close.js
Attempted import error: 'createSvgIcon' is not exported from '@material-ui/core/utils'.
Run Code Online (Sandbox Code Playgroud)

我正在尝试实现自动完成组件(来自“多个值”部分中的示例)。

这是我正在使用的代码:

import React from 'react';
import Chip from '@material-ui/core/Chip';
import Autocomplete from '@material-ui/lab/Autocomplete';
import TextField from '@material-ui/core/TextField';

<Autocomplete
        multiple
        id="tags-standard"
        options={top100Films}
        getOptionLabel={(option) => option.title}
        defaultValue={[top100Films[13]]}
        renderInput={(params) => (
          <TextField
            {...params}
            variant="standard"
            label="Multiple values"
            placeholder="Favorites"
          />
        )}
      />
Run Code Online (Sandbox Code Playgroud)

我尝试通过 NPM 安装 SVG Icons:

npm install @material-ui/icons
Run Code Online (Sandbox Code Playgroud)

然后将它们导入我的 TypeScript:

import createSvgIcon from '@material-ui/icons/utils/createSvgIcon';
Run Code Online (Sandbox Code Playgroud)

但我仍然有上面的错误。我该如何解决这个问题?

typescript reactjs material-ui

11
推荐指数
1
解决办法
3855
查看次数

从 MongoDB 填充 Material-UI DataGrid 失败,找不到唯一 ID

错误:Material-UI:数据网格组件要求所有行都具有唯一的 id 属性。当我调用表格时,我在行道具中没有提供一行是我所看到的。

这是我定义表的方式。

const columns = [
  { field: "_id", hide: true },
  { field: "user", headerName: "User", width: 70 },
  { field: "fromaddress", headerName: "Sender", width: 70 },
  { field: "dkimSpfChk", headerName: "DKIM/SPF", width: 70 },
  { field: "replySenderMismatch", headerName: "Reply MisMatch", width: 70 },
  { field: "riskywordchk", headerName: "Risky Word", width: 70 },
  { field: "domainagechk", headerName: "Sender Domain Age", width: 70 },
  { field: "attachmentChk", headerName: "Attachments", width: 70 },
  { field: "riskyLinkAge", headerName: "Body Link …
Run Code Online (Sandbox Code Playgroud)

mongodb reactjs material-ui

11
推荐指数
1
解决办法
7847
查看次数

材料 ui 实验室日期选择器,无法解析“@material-ui/lab/AdapterDateFns”

无法解析“@material-ui/lab/AdapterDateFns”

无法解析“@material-ui/lab/DateTimePicker”

无法解析“@material-ui/lab/LocalizationProvider”

即使在安装了@material-ui/lab 之后,我仍然收到这些错误

datepicker reactjs material-ui

11
推荐指数
3
解决办法
8224
查看次数

Material UI Autocomplete - 在项目选择后禁用列表框

我在Material-UI无头useAutoComplete钩子的帮助下在 React.js 中创建了一个自动完成组件。该组件工作正常。当用户尝试输入任何字符时,Listbox将自动打开。

但问题是当用户选择任何东西并注意输入元素时,ListBox重新打开。我怎样才能防止这种情况?

代码沙盒:

编辑 fg56t

代码:

import React from 'react';
import useAutocomplete from '@material-ui/lab/useAutocomplete';

function AutocompleteComponent(props) {
  const { data } = props;

  const [value, setValue] = React.useState('');
  const [isOpen, setIsOpen] = React.useState(false);

  const handleOpen = function () {
    if (value.length > 0) {
      setIsOpen(true);
    }
  };

  const handleInputChange = function (event, newInputValue) {
    setValue(newInputValue);
    if (newInputValue.length > 0) {
      setIsOpen(true);
    } else {
      setIsOpen(false);
    }
  };

  const {
    getRootProps,
    getInputProps,
    getListboxProps, …
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui

11
推荐指数
1
解决办法
258
查看次数