diff --git a/docs/src/pages/components/icons/icons.md b/docs/src/pages/components/icons/icons.md index b1ec407529c94b..208926f87f5475 100644 --- a/docs/src/pages/components/icons/icons.md +++ b/docs/src/pages/components/icons/icons.md @@ -97,7 +97,9 @@ If you need a custom SVG icon (not available in the [Material Icons](/components This component extends the native `` element: - It comes with built-in accessibility. -- SVG elements should be scaled for a 24x24px viewport so that the resulting icon can be used as is, or included as a child for other MUI components that use icons. (This can be customized with the `viewBox` attribute, to inherit `viewBox` value from original image `inheritViewBox` attribute can be used). +- SVG elements should be scaled for a 24x24px viewport so that the resulting icon can be used as is, or included as a child for other MUI components that use icons. + This can be customized with the `viewBox` attribute. + To inherit the `viewBox` value from the original image, the `inheritViewBox` attribute can be used. - By default, the component inherits the current color. Optionally, you can apply one of the theme colors using the `color` prop. ```jsx @@ -133,7 +135,7 @@ You can use the `SvgIcon` wrapper even if your icons are saved in the `.svg` for // --- import StarIcon from './star.svg'; - + ``` It's also possible to use it with "url-loader" or "file-loader". This is the approach used by Create React App. @@ -148,7 +150,7 @@ It's also possible to use it with "url-loader" or "file-loader". This is the app // --- import { ReactComponent as StarIcon } from './star.svg'; - + ``` ### createSvgIcon diff --git a/docs/translations/api-docs/svg-icon/svg-icon.json b/docs/translations/api-docs/svg-icon/svg-icon.json index bb4b9d0ddd305e..30549fcd2b7c04 100644 --- a/docs/translations/api-docs/svg-icon/svg-icon.json +++ b/docs/translations/api-docs/svg-icon/svg-icon.json @@ -7,7 +7,7 @@ "component": "The component used for the root node. Either a string to use a HTML element or a component.", "fontSize": "The fontSize applied to the icon. Defaults to 24px, but can be configure to inherit font size.", "htmlColor": "Applies a color attribute to the SVG element.", - "inheritViewBox": "Useful when you want to reference a custom component and have SvgIcon pass that component's viewBox to the root node. If true, the root node will inherit the custom component's viewBox and the viewBox prop will be ignored.", + "inheritViewBox": "If true, the root node will inherit the custom component's viewBox and the viewBox prop will be ignored. Useful when you want to reference a custom component and have SvgIcon pass that component's viewBox to the root node.", "shapeRendering": "The shape-rendering attribute. The behavior of the different options is described on the MDN Web Docs. If you are having issues with blurry icons you should investigate this prop.", "sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.", "titleAccess": "Provides a human-readable title for the element that contains it. https://www.w3.org/TR/SVG-access/#Equivalent", diff --git a/packages/mui-material/src/SvgIcon/SvgIcon.d.ts b/packages/mui-material/src/SvgIcon/SvgIcon.d.ts index 7d089ceb6a29d1..6de2b1322b487c 100644 --- a/packages/mui-material/src/SvgIcon/SvgIcon.d.ts +++ b/packages/mui-material/src/SvgIcon/SvgIcon.d.ts @@ -49,10 +49,10 @@ export interface SvgIconTypeMap

{ */ htmlColor?: string; /** - * Useful when you want to reference a custom `component` and have `SvgIcon` pass that - * `component`'s viewBox to the root node. * If `true`, the root node will inherit the custom `component`'s viewBox and the `viewBox` * prop will be ignored. + * Useful when you want to reference a custom `component` and have `SvgIcon` pass that + * `component`'s viewBox to the root node. * @default false */ inheritViewBox?: boolean; diff --git a/packages/mui-material/src/SvgIcon/SvgIcon.js b/packages/mui-material/src/SvgIcon/SvgIcon.js index d3bf57da8d9ffb..083fcf95c1f7ce 100644 --- a/packages/mui-material/src/SvgIcon/SvgIcon.js +++ b/packages/mui-material/src/SvgIcon/SvgIcon.js @@ -68,8 +68,8 @@ const SvgIcon = React.forwardRef(function SvgIcon(inProps, ref) { component = 'svg', fontSize = 'medium', htmlColor, - titleAccess, inheritViewBox = false, + titleAccess, viewBox = '0 0 24 24', ...other } = props; @@ -164,10 +164,10 @@ SvgIcon.propTypes /* remove-proptypes */ = { */ htmlColor: PropTypes.string, /** - * Useful when you want to reference a custom `component` and have `SvgIcon` pass that - * `component`'s viewBox to the root node. * If `true`, the root node will inherit the custom `component`'s viewBox and the `viewBox` * prop will be ignored. + * Useful when you want to reference a custom `component` and have `SvgIcon` pass that + * `component`'s viewBox to the root node. * @default false */ inheritViewBox: PropTypes.bool, diff --git a/packages/mui-material/src/SvgIcon/SvgIcon.test.js b/packages/mui-material/src/SvgIcon/SvgIcon.test.js index ada5bcc62a5f18..eb709681779ba3 100644 --- a/packages/mui-material/src/SvgIcon/SvgIcon.test.js +++ b/packages/mui-material/src/SvgIcon/SvgIcon.test.js @@ -98,21 +98,24 @@ describe('', () => { }); describe('prop: inheritViewBox', () => { - const customSvg = (props) => ( + const CustomSvg = (props) => ( {path} ); + it('should render with the default viewBox if neither inheritViewBox nor viewBox are provided', () => { - const { container } = render(); + const { container } = render(); expect(container.firstChild).to.have.attribute('viewBox', '0 0 24 24'); }); + it('should render with given viewBox if inheritViewBox is not provided', () => { - const { container } = render(); + const { container } = render(); expect(container.firstChild).to.have.attribute('viewBox', '0 0 30 30'); }); + it("should use the custom component's viewBox if true", () => { - const { container } = render(); + const { container } = render(); expect(container.firstChild).to.have.attribute('viewBox', '-4 -4 24 24'); }); });