Skip to content

Commit

Permalink
[Typography] Added position only when Skeleton is a direct child (#38799
Browse files Browse the repository at this point in the history
)
  • Loading branch information
siriwatknp authored Sep 5, 2023
1 parent 04b4d98 commit 846bc16
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/mui-joy/src/Typography/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ const TypographyRoot = styled('span', {
}
: {
display: 'block', // don't rely on user agent, always `block`.
position: 'relative',
...(ownerState.unstable_hasSkeleton && {
position: 'relative',
}),
}),
...((ownerState.startDecorator || ownerState.endDecorator) && {
display: 'flex',
Expand Down Expand Up @@ -189,6 +191,7 @@ const Typography = React.forwardRef(function Typography(inProps, ref) {

const level = nesting || inheriting ? inProps.level || 'inherit' : levelProp;

const hasSkeleton = isMuiElement(children, ['Skeleton']);
const component =
componentProp ||
((nesting
Expand All @@ -204,6 +207,7 @@ const Typography = React.forwardRef(function Typography(inProps, ref) {
noWrap,
nesting,
variant,
unstable_hasSkeleton: hasSkeleton,
};

const classes = useUtilityClasses(ownerState);
Expand Down Expand Up @@ -238,7 +242,7 @@ const Typography = React.forwardRef(function Typography(inProps, ref) {
<SlotStartDecorator {...startDecoratorProps}>{startDecorator}</SlotStartDecorator>
)}

{isMuiElement(children, ['Skeleton'])
{hasSkeleton
? React.cloneElement(children as React.ReactElement, {
variant: (children as React.ReactElement).props.variant || 'inline',
})
Expand Down
5 changes: 5 additions & 0 deletions packages/mui-joy/src/Typography/TypographyProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,9 @@ export interface TypographyOwnerState extends ApplyColorInversion<TypographyProp
* If `true`, the element is rendered in a Typography.
*/
nesting: boolean;
/**
* @internal
* If `true`, the Skeleton is a direct child.
*/
unstable_hasSkeleton?: boolean;
}
26 changes: 26 additions & 0 deletions test/regressions/fixtures/LinkJoy/LinkCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Card from '@mui/joy/Card';
import Link, { linkClasses } from '@mui/joy/Link';
import Typography from '@mui/joy/Typography';

export default function LinkCard() {
return (
<Box sx={{ p: 2 }}>
<Card variant="outlined" sx={{ display: 'flex', gap: 2 }}>
<Avatar size="lg" src="/static/images/avatar/1.jpg" />
<Link
overlay
href="#introduction"
underline="none"
className={linkClasses.focusVisible}
sx={{ display: 'flex', flexDirection: 'column', alignItems: 'start' }}
>
<Typography level="body-md">Joy UI</Typography>
<Typography level="body-sm">Components that spark joy!</Typography>
</Link>
</Card>
</Box>
);
}

0 comments on commit 846bc16

Please sign in to comment.