Skip to content

The open alternative to Salesforce, designed for AI.

Make twenty-ui Skeleton a block clamped to its container (#28260)

Raphaël Bosiceeb605fb795
diff --git a/packages/twenty-docs/snippets/ui/generated/feedback/skeleton.mdx b/packages/twenty-docs/snippets/ui/generated/feedback/skeleton.mdx
index 269790e7638..4b067e33f43 100644
--- a/packages/twenty-docs/snippets/ui/generated/feedback/skeleton.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/feedback/skeleton.mdx
@@ -39,8 +39,8 @@
Animated highlight color. Defaults to the theme lighter transparent background.
</ParamField>
-<ParamField body="layout" type="&quot;block&quot; | &quot;inline&quot;" default="inline">
- `inline` sizes and aligns the placeholder like a line of text. `block` renders a block without a text node, which is cheaper when many placeholders are rendered and alignment with text is not needed.
+<ParamField body="layout" type="&quot;block&quot; | &quot;inline&quot;" default="block">
+ `block` renders a block without a text node. `inline` sizes and aligns the placeholder like a line of text.
</ParamField>
<ParamField body="ref" type="Ref&lt;HTMLSpanElement&gt;">
@@ -56,5 +56,5 @@
</ParamField>
<ParamField body="width" type="Width&lt;string | number&gt;">
- Placeholder width in pixels or a CSS length. Defaults to the available width.
+ Placeholder width in pixels or a CSS length. Defaults to the available width and never exceeds the container.
</ParamField>
diff --git a/packages/twenty-docs/ui/primitives/feedback/skeleton.mdx b/packages/twenty-docs/ui/primitives/feedback/skeleton.mdx
index b47d86ca953..b393499fe42 100644
--- a/packages/twenty-docs/ui/primitives/feedback/skeleton.mdx
+++ b/packages/twenty-docs/ui/primitives/feedback/skeleton.mdx
@@ -39,6 +39,8 @@ export const LoadingProfile = () => (
);
```
+Skeleton renders as a block and never grows wider than its container. Use `layout="inline"` to place a placeholder inside a line of text.
+
Numeric dimensions use pixels. CSS lengths such as percentages and `em` are also supported. Without dimensions, the placeholder fills the available width and uses the inherited font height. Use equal dimensions and `borderRadius="50%"` for a circle.
`SKELETON_HEIGHT_SIZES` provides shared heights for `xs` (13px), `s` (16px), `m` (24px), `l` (32px) and `xl` (40px). Keep layout-specific dimensions in the application.
diff --git a/packages/twenty-front/src/modules/ai/components/LazyMarkdownRendererStyledComponents.tsx b/packages/twenty-front/src/modules/ai/components/LazyMarkdownRendererStyledComponents.tsx
index fe4f8764d45..ef589b03cca 100644
--- a/packages/twenty-front/src/modules/ai/components/LazyMarkdownRendererStyledComponents.tsx
+++ b/packages/twenty-front/src/modules/ai/components/LazyMarkdownRendererStyledComponents.tsx
@@ -158,10 +158,6 @@ export const StyledParagraph = styled.div`
export const StyledSkeletonContainer = styled.div`
max-width: 100%;
-
- [data-skeleton] {
- max-width: 100%;
- }
`;
export const StyledTableScrollContainer = styled.div`
diff --git a/packages/twenty-front/src/modules/object-record/record-board/record-board-column/components/RecordBoardColumnCardContainerSkeletonLoader.tsx b/packages/twenty-front/src/modules/object-record/record-board/record-board-column/components/RecordBoardColumnCardContainerSkeletonLoader.tsx
index 1bac34bff7f..535d922de9c 100644
--- a/packages/twenty-front/src/modules/object-record/record-board/record-board-column/components/RecordBoardColumnCardContainerSkeletonLoader.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-board/record-board-column/components/RecordBoardColumnCardContainerSkeletonLoader.tsx
@@ -55,7 +55,6 @@ export const RecordBoardColumnCardContainerSkeletonLoader = () => {
borderRadius={themeCssVariables.border.radius.sm}
width={titleSkeletonWidth}
height={12}
- style={{ display: 'block' }}
/>
</StyledSkeletonTitle>
</RecordCardHeaderContainer>
@@ -69,7 +68,6 @@ export const RecordBoardColumnCardContainerSkeletonLoader = () => {
animated={false}
baseColor={themeCssVariables.background.tertiary}
borderRadius={themeCssVariables.border.radius.sm}
- style={{ display: 'block' }}
width={16}
height={SKELETON_HEIGHT_SIZES.s}
/>
@@ -78,7 +76,6 @@ export const RecordBoardColumnCardContainerSkeletonLoader = () => {
animated={false}
baseColor={themeCssVariables.background.tertiary}
borderRadius={themeCssVariables.border.radius.sm}
- style={{ display: 'block' }}
width={151}
height={SKELETON_HEIGHT_SIZES.s}
/>
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellLoading.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellLoading.tsx
index d39e2d923fd..6d3a04d205e 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellLoading.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellLoading.tsx
@@ -23,11 +23,7 @@ export const RecordTableCellLoading = ({
widthClassName={getRecordTableColumnFieldWidthClassName(recordFieldIndex)}
isSelected={isSelected}
>
- <Skeleton
- layout="block"
- className={cellSkeletonClassName}
- animated={false}
- />
+ <Skeleton className={cellSkeletonClassName} animated={false} />
</RecordTableCellStyleWrapper>
);
};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-summary/components/__stories__/CallRecordingSummaryBody.stories.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-summary/components/__stories__/CallRecordingSummaryBody.stories.tsx
index add9aea93d2..6bb61bc5e70 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-summary/components/__stories__/CallRecordingSummaryBody.stories.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-summary/components/__stories__/CallRecordingSummaryBody.stories.tsx
@@ -163,7 +163,7 @@ export const Loading: Story = {
},
play: async ({ canvasElement }) => {
await waitFor(() => {
- expect(canvasElement.querySelector('[data-skeleton]')).toBeVisible();
+ expect(canvasElement.querySelector('[aria-busy="true"]')).toBeVisible();
});
},
};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingTranscriptBody.stories.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingTranscriptBody.stories.tsx
index 6b3d688a0e4..75ea1c91809 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingTranscriptBody.stories.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingTranscriptBody.stories.tsx
@@ -813,7 +813,7 @@ export const Loading: Story = {
},
play: async ({ canvasElement }) => {
await waitFor(() => {
- expect(canvasElement.querySelector('[data-skeleton]')).toBeVisible();
+ expect(canvasElement.querySelector('[aria-busy="true"]')).toBeVisible();
});
},
};
diff --git a/packages/twenty-front/src/modules/ui/feedback/skeleton/components/SkeletonLine.tsx b/packages/twenty-front/src/modules/ui/feedback/skeleton/components/SkeletonLine.tsx
index ca5fdf87828..bc16593c460 100644
--- a/packages/twenty-front/src/modules/ui/feedback/skeleton/components/SkeletonLine.tsx
+++ b/packages/twenty-front/src/modules/ui/feedback/skeleton/components/SkeletonLine.tsx
@@ -37,6 +37,7 @@ export const SkeletonLine = ({
{Array.from({ length: count }, (_, index) => (
<Fragment key={index}>
<Skeleton
+ layout="inline"
width={width}
height={height}
className={className}
diff --git a/packages/twenty-front/src/modules/ui/feedback/skeleton/components/__tests__/SkeletonLine.test.tsx b/packages/twenty-front/src/modules/ui/feedback/skeleton/components/__tests__/SkeletonLine.test.tsx
index 917d3977661..e9d8c3dfc9c 100644
--- a/packages/twenty-front/src/modules/ui/feedback/skeleton/components/__tests__/SkeletonLine.test.tsx
+++ b/packages/twenty-front/src/modules/ui/feedback/skeleton/components/__tests__/SkeletonLine.test.tsx
@@ -10,13 +10,14 @@ describe('SkeletonLine', () => {
expect(loadingRegions).toHaveLength(1);
expect(loadingRegion).toHaveAttribute('aria-busy', 'true');
- expect(loadingRegion.querySelectorAll('[data-skeleton]')).toHaveLength(3);
+ expect(loadingRegion.querySelectorAll('[aria-hidden="true"]')).toHaveLength(
+ 3,
+ );
expect(loadingRegion.querySelectorAll('br')).toHaveLength(3);
for (const placeholder of loadingRegion.querySelectorAll(
- '[data-skeleton]',
+ '[aria-hidden="true"]',
)) {
- expect(placeholder).toHaveAttribute('aria-hidden', 'true');
expect(placeholder.nextElementSibling?.tagName).toBe('BR');
}
});
@@ -30,7 +31,7 @@ describe('SkeletonLine', () => {
'aria-busy',
'false',
);
- expect(container.querySelector('[data-skeleton]')).not.toHaveAttribute(
+ expect(container.querySelector('[aria-hidden="true"]')).not.toHaveAttribute(
'data-animated',
);
});
diff --git a/packages/twenty-ui/docs/skeletonPropDescriptions.ts b/packages/twenty-ui/docs/skeletonPropDescriptions.ts
index ee129881bbf..3ef0a5391df 100644
--- a/packages/twenty-ui/docs/skeletonPropDescriptions.ts
+++ b/packages/twenty-ui/docs/skeletonPropDescriptions.ts
@@ -2,9 +2,9 @@ export const SKELETON_PROP_DESCRIPTIONS = {
animated:
'Animate the highlight by default. Reduced-motion preferences always disable animation.',
layout:
- '`inline` sizes and aligns the placeholder like a line of text. `block` renders a block without a text node, which is cheaper when many placeholders are rendered and alignment with text is not needed.',
+ '`block` renders a block without a text node. `inline` sizes and aligns the placeholder like a line of text.',
width:
- 'Placeholder width in pixels or a CSS length. Defaults to the available width.',
+ 'Placeholder width in pixels or a CSS length. Defaults to the available width and never exceeds the container.',
height:
'Placeholder height in pixels or a CSS length. Defaults to the inherited font height.',
borderRadius:
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 8bd56fbfade..2444095d106 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -1540,8 +1540,8 @@
"name": "layout",
"type": "\"block\" | \"inline\"",
"required": false,
- "defaultValue": "inline",
- "description": "`inline` sizes and aligns the placeholder like a line of text. `block` renders a block without a text node, which is cheaper when many placeholders are rendered and alignment with text is not needed."
+ "defaultValue": "block",
+ "description": "`block` renders a block without a text node. `inline` sizes and aligns the placeholder like a line of text."
},
{
"name": "ref",
@@ -1569,7 +1569,7 @@
"type": "Width<string | number>",
"required": false,
"defaultValue": null,
- "description": "Placeholder width in pixels or a CSS length. Defaults to the available width."
+ "description": "Placeholder width in pixels or a CSS length. Defaults to the available width and never exceeds the container."
}
]
},
diff --git a/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.module.scss b/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.module.scss
index d6c8c209700..fdd6d760a6c 100644
--- a/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.module.scss
+++ b/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.module.scss
@@ -4,16 +4,18 @@
background-color: var(--skeleton-base-color);
border-radius: 0.25rem;
- display: inline-flex;
- line-height: 1;
+ display: block;
+ height: 1em;
+ max-inline-size: 100%;
overflow: hidden;
position: relative;
user-select: none;
width: 100%;
- &[data-layout='block'] {
- display: block;
- height: 1em;
+ &[data-layout='inline'] {
+ display: inline-flex;
+ height: auto;
+ line-height: 1;
}
&[data-animated]::after {
diff --git a/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.tsx b/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.tsx
index 2dd40fba420..633b68c6ab9 100644
--- a/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.tsx
+++ b/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.tsx
@@ -13,7 +13,7 @@ export const Skeleton = ({
baseColor,
highlightColor,
animated = true,
- layout = 'inline',
+ layout = 'block',
className,
style,
render,
diff --git a/packages/twenty-ui/src/primitives/feedback/Skeleton/__stories__/Skeleton.stories.tsx b/packages/twenty-ui/src/primitives/feedback/Skeleton/__stories__/Skeleton.stories.tsx
index 2a0f9938a19..7d31240ca16 100644
--- a/packages/twenty-ui/src/primitives/feedback/Skeleton/__stories__/Skeleton.stories.tsx
+++ b/packages/twenty-ui/src/primitives/feedback/Skeleton/__stories__/Skeleton.stories.tsx
@@ -81,6 +81,27 @@ export const Default: Story = {
},
};
+export const Layouts: Story = {
+ args: { width: 400 },
+ render: (args) => (
+ <div style={{ width: 200 }}>
+ <Skeleton {...args} data-testid="block-placeholder" />
+ <Skeleton {...args} layout="inline" data-testid="inline-placeholder" />
+ </div>
+ ),
+ play: async ({ canvas }) => {
+ const blockPlaceholder = canvas.getByTestId('block-placeholder');
+ const inlinePlaceholder = canvas.getByTestId('inline-placeholder');
+
+ await expect(getComputedStyle(blockPlaceholder).display).toBe('block');
+ await expect(getComputedStyle(inlinePlaceholder).display).toBe(
+ 'inline-flex',
+ );
+ await expect(blockPlaceholder.getBoundingClientRect().width).toBe(200);
+ await expect(inlinePlaceholder.getBoundingClientRect().width).toBe(200);
+ },
+};
+
export const Static: Story = {
args: { animated: false },
};
diff --git a/packages/twenty-ui/src/primitives/feedback/Skeleton/__tests__/Skeleton.test.tsx b/packages/twenty-ui/src/primitives/feedback/Skeleton/__tests__/Skeleton.test.tsx
index 3577e888ad7..e7a4b235cce 100644
--- a/packages/twenty-ui/src/primitives/feedback/Skeleton/__tests__/Skeleton.test.tsx
+++ b/packages/twenty-ui/src/primitives/feedback/Skeleton/__tests__/Skeleton.test.tsx
@@ -43,13 +43,13 @@ it('lets native styles override dimensions and colors', () => {
});
it('keeps a text node in the inline layout so the placeholder aligns with text', () => {
- render(<Skeleton data-testid="placeholder" />);
+ render(<Skeleton data-testid="placeholder" layout="inline" />);
expect(screen.getByTestId('placeholder').textContent).toBe('‌');
});
-it('renders the block layout without a text node', () => {
- render(<Skeleton data-testid="placeholder" layout="block" />);
+it('renders the default block layout without a text node', () => {
+ render(<Skeleton data-testid="placeholder" />);
const placeholder = screen.getByTestId('placeholder');
expect(placeholder).toBeEmptyDOMElement();