Caution: React is unable to acknowledge the `textAlign` property on a DOM element

... If you deliberately want it to be displayed in the DOM as a custom attribute, spell it as lowercase textalign. If it was mistakenly transferred from a parent component, remove it from the DOM element.

Encountering this alert message while attempting to utilize styled-system with material-ui.

The snippet:

const textAlign = style({
  // React prop name
  prop: "textAlign",
  // The corresponding CSS property (defaults to prop argument)
  cssProperty: "textAlign",
  // key for theme values
  key: "textAlign",
  // accessor function for transforming the value
  transformValue: (n: string) => {
    return `${n} !important;`
  }
  // add a fallback scale object or array, if theme is not present
})

export const UiTableCell = uiTableCell`
   ${fontSize};
   ${textAlign};
   border-bottom: none !important;
   padding-top: 8px !important;
   padding-right: 20px !important; 
   padding-left: 20px !important; 
   padding-bottom: 8px !important;
   white-space: nowrap;
   position: relative;
   color: ${(props) => (props.color ? props.color : theme.colors.text)} !important;
`

and its application in a component:

<UiTableCell textAlign="right" fontSize={[2]}>
  <Text ml={[4]}>{stuff}</Text>
</UiTableCell>

Although it doesn't hinder the functionality of the app, the warning messages are cluttering the debugging console...

Answer №1

It appears that the UiTableCell component is transmitting all properties that it doesn't recognize. When it renders as a "td" tag, this creates a DOM node like:

<td textAlign="right"></td>

where the "textAlign" attribute is not interpreted as valid HTML.

Instead of directly styling UiTableCell, consider creating a wrapper component with custom styles (passed as props) and placing the UiTableCell content inside it.

You can view a full demo based on your example here: https://codesandbox.io/s/n91k87r26p

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking to properly line up and design an MUI icon button alongside a text input

After creating a modal dialog with increment and decrement buttons for text-input values, I realized it needs alignment and some styling. While the functionality is there, the appearance is lacking according to the image provided. https://i.stack.imgur.co ...

Connect this - initiate the removal of an item

I am seeking assistance from more experienced colleagues to help me understand the code below and implement it in my App. The main objective is to trigger a REDUX action from a button, which will delete an item from a database. Here is the code that curr ...

Implementing the useState Hook with Material UI Toggle Button Group in React.js

In the App.js file, I am importing Box from "@mui/system", Header from "./components/Header", ProjectList from "./components/ProjectList", CardLayout from "./components/CardLayout", and React, useState from "react". The goal here is to render the ProjectLi ...

The MUI Select component allows for showing a different value than the one that is actually selected

Within my MUI Select component, I have a list of menu items that each display an icon and text. When a menu item is selected, the value displayed in the Select component includes both the icon and text. I am wondering if it is possible to only show the t ...

Hover over with your mouse to open and close the dropdown menu in React JS

Just starting out with React JS and encountering a small issue. I'm trying to make the menu disappear when the mouse leaves that area, so I used onMouseOut and onMouseLeave to close it. However, I noticed that having these options in place prevents th ...

Next.js users have reported experiencing style flickering when utilizing material-ui's useMediaQuery feature upon initial rendering

Encountering style flickering on initial render in Next.js while using the @mui/material/useMediaQuery function. The issue arises from the useMediaQuery value changing between server side and client side rendering. Is there a solution to this problem? imp ...

Mobile devices do not support internal link scrolling in Material UI

Currently, I'm utilizing internal links like /lessons/lesson-slug#heading-slug for smooth scrolling within a page. While everything functions perfectly on desktop, it ceases to work on mobile view due to an overlaid drawer nav component. Take a look a ...

Enhanced customization of material-ui styles

After exploring various resources on styling overrides, I encountered a unique challenge. I am engaged in crafting styled material-ui components and integrating them across different sections of my application. My objective is to enable the customization o ...

Having trouble with react-testing-library and material-ui: Invalid element type error?

I encountered an issue while attempting to render a component in a react unit test, specifically with the mount method using enzyme. The error message is: Element type is invalid: expected a string (for built-in components) or a class/function (for comp ...

What is the best way to share material-ui-classes beyond my components?

In order to enhance user experience, we primarily utilize Material UI in our applications. However, a major challenge lies in syncing the styles between Material UI and plain HTML. Is there a way to expose Material-UI CSS classes so they can be used withi ...

Can you explain the significance of the "table$aria-label" and "input$autocomplete" attributes in the context of Svelte SMUI?

As a newcomer to Svelte and SMUI, I recently explored the official documentation at . I encountered some peculiar attribute declarations like "table$aria-label" and "input$autocomplete". The usage of dollar signs in naming conventions as well as the prefix ...

How can I display a minimal number of rows in a Multiline TextField in Material UI with ReactJS without any scrolling beyond that limit?

When using Material UI Texfield for multiline input, I am looking to display a minimum of 3 rows initially and then have the text area expand further without showing a scroll bar if the content exceeds 3 rows. I attempted the following: <TextFi ...

Material-UI offers a feature known as the Multiple selector, which

I am looking to create a multiple selector with predefined choices for users to select from. This image (link: https://i.stack.imgur.com/Ap7jL.png) shows the desired functionality. Initially, I considered using the <Switch> component but it didn&ap ...

Using material-ui to derive color from the theme

I am looking to utilize a color from my material-ui theme within a component, like so: const MyComponent = props => ( <UsersIcon color={currentTheme.primary1Color} /> ) My goal is to extract a value from the current theme provided. I have co ...

The MUI Slider Component is causing the entire page to go blank

I have implemented the Range Slider component: import React from 'react'; import Box from '@mui/material/Box'; import Slider from '@mui/material/Slider'; function valuetext(value) { return `${value}°C`; } export default f ...

Implementing defaultProps in conjunction with withStyles

Currently, I am in the process of developing a component using material-ui withStylers and defaultProps. However, I have encountered an issue where the props of the component are not being retrieved in the styles objects unless they are explicitly passed t ...

Unable to customize the default styling of Material UI Icons

I am trying to increase the size of an AccountCircleIcon Material UI icon, but I have attempted various methods: import AccountCircleIcon from '@material-ui/icons/AccountCircle'; import {withStyles} from '@material-ui/styles'; const St ...

Customizing the appearance of individual columns in the Material-UI DataGrid

My goal is to center an IconButton within a DataGrid table, all of which are MUI components. Despite reading the documentation and trying various methods, I haven't achieved the desired result yet. In my latest attempt, I implemented the following: G ...

React/Typescript - Managing various event types within a unified onChange function

In my current project, I am working with a form that includes various types of input fields using the mui library. My goal is to gather the values from these diverse input components and store them in a single state within a Grandparent component. While I ...

Tips and tricks for setting up a functional react select component using Material UI

Having an issue with React Select material UI where the dropdown select is not functioning properly. The popup does not open up as expected. I am looking to display react select in a modal dialog box. import MenuItem from "@mui/material/MenuItem" ...