<bdo id='XPDGL'></bdo><ul id='XPDGL'></ul>

    1. <tfoot id='XPDGL'></tfoot>
      <i id='XPDGL'><tr id='XPDGL'><dt id='XPDGL'><q id='XPDGL'><span id='XPDGL'><b id='XPDGL'><form id='XPDGL'><ins id='XPDGL'></ins><ul id='XPDGL'></ul><sub id='XPDGL'></sub></form><legend id='XPDGL'></legend><bdo id='XPDGL'><pre id='XPDGL'><center id='XPDGL'></center></pre></bdo></b><th id='XPDGL'></th></span></q></dt></tr></i><div id='XPDGL'><tfoot id='XPDGL'></tfoot><dl id='XPDGL'><fieldset id='XPDGL'></fieldset></dl></div>
      <legend id='XPDGL'><style id='XPDGL'><dir id='XPDGL'><q id='XPDGL'></q></dir></style></legend>
      1. <small id='XPDGL'></small><noframes id='XPDGL'>

        如何更改材质ui表中所选行的文本颜色

        时间:2023-09-05

                <tbody id='lUQeF'></tbody>
              <legend id='lUQeF'><style id='lUQeF'><dir id='lUQeF'><q id='lUQeF'></q></dir></style></legend>

              <small id='lUQeF'></small><noframes id='lUQeF'>

              <i id='lUQeF'><tr id='lUQeF'><dt id='lUQeF'><q id='lUQeF'><span id='lUQeF'><b id='lUQeF'><form id='lUQeF'><ins id='lUQeF'></ins><ul id='lUQeF'></ul><sub id='lUQeF'></sub></form><legend id='lUQeF'></legend><bdo id='lUQeF'><pre id='lUQeF'><center id='lUQeF'></center></pre></bdo></b><th id='lUQeF'></th></span></q></dt></tr></i><div id='lUQeF'><tfoot id='lUQeF'></tfoot><dl id='lUQeF'><fieldset id='lUQeF'></fieldset></dl></div>
            • <tfoot id='lUQeF'></tfoot>
                • <bdo id='lUQeF'></bdo><ul id='lUQeF'></ul>

                  本文介绍了如何更改材质ui表中所选行的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试更改行文本的颜色和选择时行的背景颜色.

                  我可以成功更改背景颜色,但无法更改文本颜色.

                  解决方案

                  背景颜色控制在

                  这里有一个类似的例子,但是使用了selected".而不是悬停":

                  I am trying to change the color of the row text and the background color of row on selection.

                  I am able to change the background color successfully but I am not able to change the text color.

                  <TableRow
                          className={classes.tableBody}
                        >
                  
                  tableBody: {
                      "&:focus": {
                        color: "yellow !important",
                        backgroundColor: "#3D85D2 !important",
                      },
                    },
                  

                  解决方案

                  The background color is controlled in TableRow. In order to get the correct specificity (you shouldn't ever need to leverage "!important" when overriding Material-UI styles), you need to leverage the "hover" class similar to what is done within TableRow.

                  The color is controlled in TableCell, so that is the level where you need to control it.

                  For a working solution, in the styles you would have something like:

                  const styles = theme => ({
                    tableRow: {
                      "&$hover:hover": {
                        backgroundColor: "blue"
                      }
                    },
                    tableCell: {
                      "$hover:hover &": {
                        color: "pink"
                      }
                    },
                    hover: {}
                  });
                  

                  then in the rendering:

                              <TableRow
                                hover
                                key={row.id}
                                classes={{ hover: classes.hover }}
                                className={classes.tableRow}
                              >
                                <TableCell
                                  className={classes.tableCell}
                                  component="th"
                                  scope="row"
                                >
                                  {row.name}
                                </TableCell>
                  

                  Here's a working version based on your sandbox:

                  Here's a similar example, but using "selected" instead of "hover":

                  https://codesandbox.io/s/llyqqwmr79

                  This uses the following styles:

                  const styles = theme => ({
                    tableRow: {
                      "&$selected, &$selected:hover": {
                        backgroundColor: "purple"
                      }
                    },
                    tableCell: {
                      "$selected &": {
                        color: "yellow"
                      }
                    },
                    selected: {}
                  });
                  

                  and some state:

                   const [selectedID, setSelectedID] = useState(null);
                  

                  and changing the TableRow rendering to be:

                              <TableRow
                                hover
                                key={row.id}
                                onClick={() => {
                                  setSelectedID(row.id);
                                }}
                                selected={selectedID === row.id}
                                classes={{ selected: classes.selected }}
                                className={classes.tableRow}
                              >
                  

                  v4 of Material-UI will include some changes that should make overriding styles considerably easier (and easier to figure out how to do successfully without looking at the source code).

                  In v4 of Material-UI, we can use the global class names for the selected state ("Mui-selected") and for TableCell ("MuiTableCell-root") and then we only need to apply a single class to TableRow:

                  const styles = (theme) => ({
                    tableRow: {
                      "&.Mui-selected, &.Mui-selected:hover": {
                        backgroundColor: "purple",
                        "& > .MuiTableCell-root": {
                          color: "yellow"
                        }
                      }
                    }
                  });
                  

                  这篇关于如何更改材质ui表中所选行的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  • <small id='35J6e'></small><noframes id='35J6e'>

                      • <bdo id='35J6e'></bdo><ul id='35J6e'></ul>

                          <legend id='35J6e'><style id='35J6e'><dir id='35J6e'><q id='35J6e'></q></dir></style></legend>
                          <i id='35J6e'><tr id='35J6e'><dt id='35J6e'><q id='35J6e'><span id='35J6e'><b id='35J6e'><form id='35J6e'><ins id='35J6e'></ins><ul id='35J6e'></ul><sub id='35J6e'></sub></form><legend id='35J6e'></legend><bdo id='35J6e'><pre id='35J6e'><center id='35J6e'></center></pre></bdo></b><th id='35J6e'></th></span></q></dt></tr></i><div id='35J6e'><tfoot id='35J6e'></tfoot><dl id='35J6e'><fieldset id='35J6e'></fieldset></dl></div>
                            <tbody id='35J6e'></tbody>

                          <tfoot id='35J6e'></tfoot>