重复问题
- 我搜索了现有的问题
最新版本
- 我测试了最新版本
重现步骤 🕹
链接到实时示例:https://codesandbox.io/p/sandbox/blissful-night-4v3x2j?file=%2Fsrc%2FDemo.tsx(官方“Material UI Icons Size doc”中可用的Codesandbox IDE中的实时示例)
正如您所看到的,即使在官方文档的实时示例代码sandbox IDE中也会出现这种情况。
步骤:
- 在您的代码中包含任何Material UI图标。例如:
import Person from '@mui/icons-material/Person';
...
<Person />
- 将它添加到fontSize属性中,使用任何官方支持的尺寸(xs、sm、md、lg、xl、xl2、xl3或xl4):
import Person from '@mui/icons-material/Person';
...
<Person fontSize="xl2" />
- 您将看到应用了图标大小,但是代码会被TypeScript错误高亮显示,告知仅支持的尺寸是“small、medium或large”,而如果您遵循了“Material UI Icons Installation instructions”,这些值实际上都不起作用。
当前行为 😯
- 在fontSize属性中放入正确的值(xs、sm、md、lg、xl、xl2、xl3或xl4)可以正常工作,但是会引发TypeScript错误。
- 在fontSize属性中放入不正确的值(small、medium或large)无法正常工作,但TypeScript却喜欢它。
预期行为 🤔
- 在fontSize属性中放入正确的值(xs、sm、md、lg、xl、xl2、xl3或xl4)可以正常工作且TypeScript喜欢它。
- 在fontSize属性中放入不正确的值(small、medium或large)无法正常工作且TypeScript会引发错误。
上下文 🔦
只是尝试使用官方的fontSize属性自定义应用程序内的图标大小,以避免CSS粒度定制。
您的环境 🌎
npx @mui/envinfo
System:
OS: Windows 11 10.0.22631
Binaries:
Node: 18.17.0 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 120.0.6099.111 (Build oficial) (64 bits)
Firefox: 121.0 (64-bit)
Edge: 120.0.2210.77 (Compilación oficial) (64 bits)
npmPackages:
@emotion/react: ^11.11.3 => 11.11.3
@emotion/styled: ^11.11.0 => 11.11.0
@mui/base: 5.0.0-beta.29
@mui/core-downloads-tracker: 5.15.2
@mui/icons-material: ^5.15.2 => 5.15.2
@mui/joy: ^5.0.0-beta.20 => 5.0.0-beta.20
@mui/material: ^5.15.2 => 5.15.2
@mui/private-theming: 5.15.2
@mui/styled-engine: 5.15.2
@mui/system: ^5.15.2 => 5.15.2
@mui/types: 7.2.11
@mui/utils: 5.15.2
@types/react: 18.2.20 => 18.2.20
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
typescript: 5.1.6 => 5.1.6
tsconfig
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"],
"@mui/material": ["./node_modules/@mui/joy"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
1条答案
按热度按时间jobtbby31#
我认为,作为解决方法,你可以将以下内容添加到你的应用程序或主题文件中: