DEV Community

Cover image for 5 Things AI Can't Do, Even in • Material UI (MUI)
DevUnionX
DevUnionX

Posted on

5 Things AI Can't Do, Even in • Material UI (MUI)

This analysis examines in depth the challenges and limitations AI can encounter even in current Material UI versions. We address five main topics extending from semantic structure starting with MUI component API to style system and theme compatibility, responsive layout rules, accessibility integration, and build performance in scaled applications. For each topic we'll explain the relevant MUI feature technically, show concrete failure modes of AI production with examples, support with real-world cases, and present improvement strategies for developers.

For instance, in MUI the List component by default creates a ul element but should be changed to nav with component equals nav. AI might not always correctly grasp which HTML element components fundamentally correspond to. On the other hand, the style system contains nuances like using Emotion instead of JSS in MUI v5, requiring old JSS selectors like ampersand dollar sign focused to be replaced with new class names like .Mui-focused. As AI generates code quickly, it might not see these differences and continue using makeStyles or JSS syntax. Similarly, using grid and breakpoints like xs, sm, md is essential for responsive layout rules, but AI has been reported to sometimes create incomplete or incorrect responsive configuration.

In accessibility, though MUI integrates many components with ARIA roles, for instance dialogs offer modal role and focus trap, some scenarios have deficiencies like DataGrid lacking aria-label on row selection icons. AI might not see these subtleties, leading to accessibility warnings. Finally, in build and package optimization, recommendations AI overlooks like using barrel imports can negatively affect performance. Official sources recommend direct file-based imports. We provide comparison of human-crafted MUI code versus AI outputs with table and flowchart, presenting developer and AI workflow flow diagram. In conclusion, though AI accelerates coding, achieving full compliance with MUI's complex API, conforming to semantic and accessibility rules, and ensuring theme and brand integrity still require human-based review and correction.

Material UI offers the ability to control the underlying HTML tag and additional properties of each component with props like component. This creates correct semantic HTML like headings and lists. For example, a List component by default produces ul tag but can also be rendered as menu by saying component equals menu. Similarly, Typography component transforms into appropriate heading h1 through h6 or paragraph p element with variant prop. In the following example, using component equals nav and aria-label provides navigation list semantics.

Import List, ListItem, ListItemText, Typography, Button, IconButton from @mui/material. List component uses ul by default. With component equals nav, nav tag was used. List component nav aria-label Main Menu. ListItem with ListItemText primary Homepage. ListItem with ListItemText primary About Us. Typography component with variant h1 produces an h1 tag. Typography variant h1 Site Title. Icon-based buttons like IconButton must definitely have aria-label added. IconButton aria-label Delete with DeleteIcon.

AI output generally misses these subtle semantic nuances. For instance AI might mistakenly use div instead of List or drop the variant prop for Typography falling to simple p tag. With MUI's component and variant features, tags critical for accessibility and SEO should be managed correctly. Error rate in a PR generated by AI was found approximately 1.7 times higher compared to human code. Many of these errors can stem from such semantic mistakes. Additionally, some MUI components carry static properties like muiName, for example Icon component. This can be important in advanced wrapping with props. Consequently, developers must always compare code coming from AI with component documentation and check semantic consistency.

Failure modes: AI might skip the component property of MUI components and use wrong HTML tag. Might not specify correct variant in Typography and miss headings. Might forget to add aria-label to buttons containing icons. For instance according to a GitHub report seen in MUI data grid, the rows per page option dropdown icon gives form label missing warning due to lack of aria-label. While human developer catches such deficiencies directly with tests and ARIA guidelines, AI might not see this.

Example: In the above code our list creates a semantic navigation menu over nav and our button is labeled with aria-label. If we had used div instead of List, screen readers couldn't correctly identify navigation structure. When AI doesn't do this, accessibility and SEO problems emerge. Developer strategies: Code should be examined carefully to reduce semantic AI errors. Component API documents and W3C ARIA guidelines should be referenced, for instance in Modal/Dialog component if usage of role, aria-labelledby and aria-describedby isn't documented by MUI it should be added. Props like component and variant should be used consciously, correcting semantic details AI skipped manually.

Additionally, AI suggestions using icons inside IconButton or Button must definitely have aria-label added or accessibility provided with labels like title inside svg. Semantic errors can be caught with automated tests in code review processes, for example axe-core. MUI's style system is quite flexible but contains details. AI can overlook these nuances. First, the sx prop is the ideal method for adding style specific to a single component. For example: import Button from @mui/material. Button sx padding 2 color primary.contrastText Click. In this code sx padding 2 uses theme units and adds prioritized style with CSS-in-JS. AI sometimes tends to use style property instead of sx or even plain CSS files, thus skipping MUI theme.

The sx works on all MUI components and provides easy access to design tokens in theme like theme.spacing and palette. For broader customizations, you can create new components with MUI's styled helper function. For example: import styled from @mui/material/styles and import Button. Const CustomButton equals styled Button with theme showing backgroundColor theme.palette.primary.main and hover backgroundColor theme.palette.primary.dark. In this example theme colors were used. This example creates custom button style using theme. In AI code we generally see fixed color values. This can be incompatible with brand's dynamic theme.

In a good MUI application, values like color and typography get managed centrally using theme settings. Additional variables and type extensions can be made in theme with createTheme. AI might skip these steps and write style directly. With MUI v5, Emotion is used instead of JSS. AI knowing old version JSS syntax might continue using old selectors like ampersand dollar sign focused which don't work in Emotion. For instance below, old JSS syntax on left and required Emotion equivalent in v5 on right.

JSS v4 usage wrong in Emotion. MuiOutlinedInput styleOverrides root with ampersand dollar sign focused borderWidth 2 as JSS variable doesn't wake, ampersand space dollar sign notchedOutline borderWidth 1 as local rule reference. Emotion v5 correct usage. Components MuiOutlinedInput styleOverrides root with ampersand .Mui-focused borderWidth 2 as new global class, ampersand space .MuiOutlinedInput-notchedOutline borderWidth 1 as global class.

A model that can rapidly produce code might not abandon old JSS habits. However MUI documents clearly state: replace JSS usage like dollar sign focused with .Mui-focused in Emotion. Therefore AI has possibility of using wrong syntax in style block creating non-working CSS. Failure modes: AI can make these mistakes: using inline style or global CSS instead of sx, creating style with fixed values skipping theme, continuing to use old JSS syntax like ampersand dollar sign focused and array-based values incompatible with Emotion, not using string values instead of CSS important or JSS-specific matrix values like padding double bracket 5,8,6.

These situations lead to style not being applied or unexpected results. For instance as you'll see in migration documentation, array usage is no longer supported and should be fixed this way. If AI leaves generated code untested, these CSS errors can be overlooked. Example: AI can write background with JSS-style matrix. Wrong JSS arrays. Root background as array url img1.png no-repeat top, url img2.png no-repeat center, exclamation important. Fixed for Emotion. Root background url img1.png no-repeat top comma url img2.png no-repeat center space exclamation important. In this example when left to AI, second lines remain as broken CSS.

Developer strategies: To prevent style errors, sx and styled usage guides should be followed. If theme extension is needed, it must definitely be done with createTheme. Migration guide should be checked and AI's old JSS habits manually corrected. By adding CSS validation to code review and test processes, for example stylelint and jest with snapshot tests, errors can be caught early. Additionally, instead of old JSS solutions like @mui/styles, Emotion or styled-components that come as default in foundation should be preferred. AI codes should be translated understandably as they might conflict with this integration.

MUI offers comprehensive grid and breakpoint system for responsive design. For instance default 5 breakpoints xs sm md lg xl correspond to 0, 600, 900, 1200, 1536 pixel widths respectively. Layout quickly adapts using Grid or useMediaQuery with these breakpoints. But incorrect application of these rules leads to failure modes. For instance Grid component is flexbox-based and requires container and item props to be appropriately set for correct functioning. If a developer or AI only uses Grid forgetting container prop, rows behave as single column.

The following example shows typical column layout. Grid container spacing 2. Container prop started row. Grid item xs 12 md 8. When screen is xs full width, md and above 8 out of 12 width. Typography Content 1. Grid item xs 12 md 4. Typography Content 2. In this code xs 12 means each grid item full width on mobile, md 4 means using 4 of 12 columns on medium and larger screens. AI sometimes might assign numeric keys incompletely or try using in single tag like Grid xs 12 md 6 which belongs to old v4 API. In MUI v5 even if item prop isn't written explicitly, using at least container shouldn't be forgotten.

Not understanding Grid constraints also creates errors. Though MUI Grid is flexible, when single row doesn't fit it moves to next row. Columns split and slide to another row. Row span support doesn't exist and automatic placement isn't offered. For this CSS Grid is recommended. AI with incomplete knowledge might expect row-span or automatic flex wrap with Grid. For instance while props like justifyContent center work inside Grid container, advanced design doesn't support some grid features. Additionally when AI sometimes uses fixed pixels instead of full range values for responsive layout, like theme.breakpoints.between, unexpected results can occur.

MUI documents provide helper functions like theme.breakpoints.up/down/only for responsive styles. With MUI v5 breakpoint names can be customized, for example mobile tablet desktop, but when customizing note that all values need to be added into theme. Otherwise you get API error. Failure modes: Responsive codes AI publishes generally contain several type errors: missing container and item usage, using only size or similar old API instead of props like xs sm md, misunderstanding grid's 12-column structure like total exceeding 12, neglecting system not supporting row jumping or column merging, incorrectly using fixed width or useMediaQuery.

For instance according to a StackOverflow topic, though MUI Grid container breakpoints look correct, applications like md for container might not work, an issue mentions breakpoint for container doesn't exist. AI-assisted tool might skip these nuances without examining MUI documentation. Example: In above code layout defined with md 8 and md 4. On medium-size screens first item covers 8 columns, second 4 columns. If AI mistakenly specified incomplete like xs 6 sm 3 instead of xs 6 md 8, layout can break on wide screens.

Developer strategies: Responsive design should be validated. In code review, ensure container or item props are appropriate for each Grid element. Props like spacing and justifyContent should be tested. AI output should be used as temporary prototype but validated with responsiveness tests, manual checks at different screen sizes, jest plus jest-viewport. If needed, transition to CSS Grid or solve boundary problems by adding additional media queries. Additionally MUI container like Container can be used to limit centered page area. Remember AI code tends to ignore such MUI helper components.

Though MUI components generally support accessibility a11y rules, some situations require additional attention. According to Material Design guidelines, components like dialogs, modals, and menus should be given relevant ARIA properties. For instance when a Dialog component opens, screen reader should announce to user as modal dialog and should reference a title with aria-labelledby and content with aria-describedby. However it's been reported that MUI's default Dialog demo page lacks these labels and screen reader missed content announcement. AI might not remember this detail.

As code snippet, an example about adding ARIA. Import Dialog, DialogTitle, DialogContent, DialogActions, Button from @mui/material. Dialog open equals open onClose equals handleClose aria-labelledby dialog-title aria-describedby dialog-desc. DialogTitle id dialog-title Confirm Operation. DialogContent id dialog-desc This is permanent operation. Are you sure you want to continue. DialogActions. Button onClick handleClose autoFocus Cancel. Button onClick handleConfirm OK. With additional properties above, screen reader reads title and description correctly. ARIA labels added in above code enable understanding dialog content conforming to WAI-ARIA application example.

In AI code these aria attributes can generally be missing. Additionally giving meaningful labels to UI elements is important. Buttons containing icons like IconButton must definitely have aria-label, otherwise screen reader perceives button as meaningless blank. In an issue reported on GitHub, MUI Select and DataGrid menus got form label missing error due to dropdown icon lacking aria-label. Such subtle problems can be overlooked in unchecked version of code AI produces. MUI also does focus management for some dynamic states, for instance when dialog opens focuses on first button.

Still in a StackOverflow question, aria-hidden warning was received when dialog closed and this turned out to be a problem related to MUI's focus management. In this case, trying to hide a focused element after dialog closed created warning, according to WAI-ARIA specification element to which aria-hidden will be applied shouldn't take focus. Code left to AI can lead to such interaction warnings. Failure modes: In MUI JSX AI creates, generally these deficiencies can be seen: skipping aria-label or aria-labelledby, not adding appropriate role like role dialog and labels in dialog/modal, focus management errors.

For instance AI might not add ARIA labels to Dialog component or might not add aria-label to IconButton. This produces both accessibility error and compliance warning. In code review as seen in examples, when guiding labels aren't added users can't be directed, screen readers can't provide information, tools like Wave and Lighthouse find deficiencies. Example: AI can create missing label like below. IconButton with MailIcon. No aria-label. In this code AI only showed button to browser with icon and didn't label it. To ensure accessibility: IconButton aria-label Send Mail with MailIcon. Should be arranged this way.

Developer strategies: Accessibility check must definitely be done in code review, for example Chrome Lighthouse and axe devtools. A11y tips from official component documentation should be followed and ARIA additions manually added when needed. Attention should be paid to title and content labeling in components like Dialog with aria-labelledby and describedby. AI code should be compared with reliable human-written accessibility guide or tool like WCAG checklist to fix errors. For instance criteria like WCAG 2.5.8 target size and 2.4.11 focus must be visible determine touch width and focus style of MUI components. Consequently, AI suggestions should always be supervised by accessibility expert or experienced developer.

In large-scale projects using MUI, project structure and build settings become critical for performance and maintenance. MUI documentation has various recommendations to minimize package size. For instance, barrel or top-level imports like import Button from @mui/material extend packaging times during development. Instead importing piece by piece directly like import Button from @mui/material/Button is recommended. If AI produced, it might skip such nuances and easily write import Button TextField from @mui/material. This can result in 6 times slower loading especially in icon packages.

The following example shows preferred and avoided import. Checkmark preferred direct file import. Import Button from @mui/material/Button. Import TextField from @mui/material/TextField. X mark avoided barrel import reduces development performance. Import Button TextField from @mui/material. According to official guide, though Next.js 13.5 plus projects have automatic import optimization, in ordinary React applications developer needs to follow this rule

AI-assisted tools don't know such long-term configuration needs of project. Codemod might need to be manually run on AI-produced code. Besides this, for bundle size optimization make sure you use ES modules suitable for react tree-shaking. From MUI v5 onwards each component is offered in separate packages, so check with Chrome DevTools or tools like bundlephobia to see which modules are included. AI can fall into error of fetching inactive styles like import asterisk or loading entire X packages

Failure modes: AI output generally comes with crude imports: barrel imports, require-style imports, or lines loading entire library like import @mui/material. This situation especially negatively affects bundle size and build time criteria in large projects. AI doesn't automatically add theme or additional configuration, for example compatibility code with competing integrated systems like Next.js or Tailwind. In tool chain, problems can emerge like managing unused CSS independent of code, for example collecting all style files from within node_module.

Example table: Below table compares AI versus human-generated code. Here correctness reflects perception accuracy, accessibility reflects WCAG compliance, maintainability reflects code quality, package size reflects import optimization, and brand fit reflects design conformance scoring. AI-assisted code has been shown in studies to have 1.7 percent more errors compared to human code, indicating both accessibility and maintenance difficulties. The table shows characteristic, AI-generated, and Human-generated columns.

Correctness: Lower with 1.7 times more errors, incorrect or incomplete component property usage versus High, validated with documentation and tests. Accessibility: Weak with most ARIA and labels missing, problematic in accessibility tests versus Good, compliant with WCAG and ARIA guidelines with deficiencies manually checked. Maintainability: Low with complex and old pattern usage versus High with themed modular code, comments and standard-compliant. Package Size: Large with barrel import and tree-shaking avoided versus Optimal with import from correct paths and when codemod is activated. Brand Fit: Low with default colors and themes, custom style can be skipped versus High with theme variables and custom SCSS/vars applied.

Flowchart: The following mermaid diagram shows example workflow between developer and AI. First project requirements and brand guidelines are defined. Developer requests draft code from AI and obtains production. AI output gets pre-checked according to version compatibility and basic API rules. If problem exists, for example if v4 was used to use sx/styled instead of makeStyles, process returns. Then functionality and responsive layout tests are done, errors manually corrected. Accessibility tests like axe if problem ARIA gets added. Finally package size and performance checked and necessary optimizations done.

The flowchart shows: Project requirements including theme, accessibility standards. Contracts including MUI documentation and code standards. AI initial draft with JSX/TSX, theme settings, sx and styled examples. Decision whether version compatibility correct, v5 verified. If no, transform code according to V5 documentation and return. If yes, decision whether component operation check correct elements. If no return. If yes decision whether responsive test grid breakpoints correct. If no return. If yes decision whether accessibility test ARIA and labels exist. If no add ARIA check focus management and return. If yes decision whether bundle check imports optimized. If no optimize with Babel/ESLint apply codemod and return. If yes final checks including code review and performance tests.

Sources: In this report, MUI official documents including customization guides, component APIs, version migration guides, GitHub and StackOverflow accessibility and case studies, and artificial intelligence code generation research were used. Code examples and tables were also prepared in line with these sources. In conclusion, in a rich component library like MUI, though benefiting from AI is possible, human supervision and expertise remain indispensable.

Top comments (0)