diff --git a/docs/pages/api/avatar-group.md b/docs/pages/api/avatar-group.md index 3c18e082d6c21e..b58ca8a30319a0 100644 --- a/docs/pages/api/avatar-group.md +++ b/docs/pages/api/avatar-group.md @@ -26,8 +26,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi |:-----|:-----|:--------|:------------| | children | node | | The avatars to stack. | | classes | object | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. | -| spacing | 'small'
| 'medium'
| 'large'
| number
| | Defines the spacing between `avatar` as `'large': -4px`, `'medium': -8px`, and `'small': -16px` or define a `number` as the spacing. | - +| spacing | 'large'
| 'medium'
| 'small'
| number
| 'medium' | Spacing between avatars. | The `ref` is forwarded to the root element. diff --git a/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.d.ts b/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.d.ts index 6431f8b37ffc2d..7786af1a461c09 100644 --- a/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.d.ts +++ b/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.d.ts @@ -15,4 +15,4 @@ export interface AvatarGroupProps export type AvatarGroupClassKey = 'root' | 'avatar'; -export default function AvatarGroup(props: AvatarGroupProps): JSX.Element | null; +export default function AvatarGroup(props: AvatarGroupProps): JSX.Element; diff --git a/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js b/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js index e94524d838f5b0..eefc96f12adb20 100644 --- a/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js +++ b/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js @@ -5,9 +5,8 @@ import clsx from 'clsx'; import { withStyles } from '@material-ui/core/styles'; const SPACINGS = { - large: -4, - medium: -8, - small: -16 + large: -4, + small: -16, }; export const styles = theme => ({ @@ -18,11 +17,13 @@ export const styles = theme => ({ /* Styles applied to the avatar elements. */ avatar: { border: `2px solid ${theme.palette.background.default}`, + marginLeft: -8, }, }); const AvatarGroup = React.forwardRef(function AvatarGroup(props, ref) { - const { children: childrenProp, classes, className, spacing, ...other } = props; + const { children: childrenProp, classes, className, spacing = 'medium', ...other } = props; + const children = React.Children.toArray(childrenProp).filter(child => { if (process.env.NODE_ENV !== 'production') { if (isFragment(child)) { @@ -45,7 +46,7 @@ const AvatarGroup = React.forwardRef(function AvatarGroup(props, ref) { className: clsx(child.props.className, classes.avatar), style: { zIndex: children.length - index, - marginLeft: spacing ? (SPACINGS[spacing] ? SPACINGS[spacing] : spacing) : -8, + marginLeft: spacing && SPACINGS[spacing] ? SPACINGS[spacing] : -spacing, ...child.props.style, }, }); @@ -68,14 +69,14 @@ AvatarGroup.propTypes = { * See [CSS API](#css) below for more details. */ classes: PropTypes.object, - /** - * Spacing between avatars. - */ - spacing: PropTypes.oneOfType([PropTypes.oneOf(['large', 'medium', 'small']), PropTypes.number]), /** * @ignore */ className: PropTypes.string, + /** + * Spacing between avatars. + */ + spacing: PropTypes.oneOfType([PropTypes.oneOf(['large', 'medium', 'small']), PropTypes.number]), }; export default withStyles(styles, { name: 'MuiAvatarGroup' })(AvatarGroup);