Skip to content

Commit ec67b3d

Browse files
authored
[Markdown] Fix layout issues for markdown embeddables in small panels (elastic#240806)
## Summary Fixes layout issues for markdown embeddables in small dashboard panels using CSS container queries. When a markdown panel is shorter than 120px, the UI now adapts to a compact layout that maximizes usable space. ## Problem Markdown embeddables are not rendering correctly in small (short) panels. The editor toolbar and footer would take up significant vertical space, leaving little room for content editing in constrained layouts. Turns out that this usecase can be more important to just ignore it, since users might use small panels to only place the title in the dashboard. <img width="643" height="89" alt="Screenshot 2025-10-27 at 14 08 42" src="https://github.com/user-attachments/assets/b3478586-13d0-4ef0-b5b5-617089886db3" /> ## Solution ### Layout Improvements Implemented responsive layout using CSS container queries (@container) to detect when panels are too small and automatically switch to a compact layout: When container height < 120px: - Editor toolbar is hidden to maximize editing space - toolbar can be useful but it's not essential for the users to edit their markdown panels. - Footer transforms to compact overlay positioned in the top-right corner with transparent background <img width="640" height="83" alt="Screenshot 2025-10-27 at 14 08 17" src="https://github.com/user-attachments/assets/14582c1a-1f56-42bf-9f63-4bd1a1add77e" /> The new layout <img width="581" height="186" alt="Screenshot 2025-10-27 at 14 13 31" src="https://github.com/user-attachments/assets/8982f333-5133-4fbb-b94b-815cb28b61de" /> The smallest layout that still follows the 'classic' design
1 parent 73ec8eb commit ec67b3d

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/platform/plugins/shared/dashboard_markdown/public/components/markdown_editor.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { PublishingSubject } from '@kbn/presentation-publishing';
1515
import { useStateFromPublishingSubject } from '@kbn/presentation-publishing';
1616
import React, { useLayoutEffect, useRef } from 'react';
1717
import { useMemoCss } from '@kbn/css-utils/public/use_memo_css';
18-
import { FOOTER_HELP_TEXT, MarkdownFooter } from './markdown_footer';
18+
import { SHORT_CONTAINER_QUERY, FOOTER_HELP_TEXT, MarkdownFooter } from './markdown_footer';
1919
import { MarkdownRenderer } from './markdown_renderer';
2020

2121
interface EuiMarkdownEditorRef {
@@ -24,6 +24,11 @@ interface EuiMarkdownEditorRef {
2424
}
2525

2626
const componentStyles = {
27+
rootContainer: css({
28+
display: 'flex',
29+
width: '100%',
30+
containerType: 'size',
31+
}),
2732
container: css({
2833
width: '100%',
2934
}),
@@ -43,6 +48,13 @@ const componentStyles = {
4348
textarea: {
4449
minBlockSize: 'initial',
4550
},
51+
[SHORT_CONTAINER_QUERY]: {
52+
blockSize: `100%`,
53+
// TODO: Do not use data-test-subj to style - should be fixed in EUI
54+
'[data-test-subj="euiMarkdownEditorToolbar"]': {
55+
display: 'none',
56+
},
57+
},
4658
}),
4759
};
4860

@@ -82,7 +94,7 @@ export const MarkdownEditor = ({
8294
const isSaveable = Boolean(value === '' || value !== content);
8395

8496
return (
85-
<>
97+
<div css={styles.rootContainer}>
8698
<div
8799
css={[styles.container, isPreview && styles.componentInvisible]}
88100
onKeyDown={(e) => {
@@ -117,7 +129,7 @@ export const MarkdownEditor = ({
117129
cancelButtonRef={cancelButtonRef}
118130
isSaveable={isSaveable}
119131
/>
120-
</>
132+
</div>
121133
);
122134
};
123135

src/platform/plugins/shared/dashboard_markdown/public/components/markdown_footer.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import { i18n } from '@kbn/i18n';
2424

2525
export const FOOTER_HELP_TEXT = htmlIdGenerator()('markdownEditorFooterHelp');
2626

27+
// Container query for when the height is too short and we need to switch to a more compact layout
28+
export const SHORT_CONTAINER_QUERY = `@container (max-height: 119px)`;
29+
2730
const footerStyles = {
2831
footer: ({ euiTheme }: UseEuiTheme) =>
2932
css({
30-
padding: euiTheme.size.s,
3133
borderRadius: `0 0 ${euiTheme.size.s} ${euiTheme.size.s}`,
3234
width: '100%',
3335
borderTop: `1px solid ${euiTheme.colors.borderBasePlain}`,
@@ -40,10 +42,21 @@ const footerStyles = {
4042
opacity: 0.9,
4143
inset: 0,
4244
},
45+
[SHORT_CONTAINER_QUERY]: {
46+
borderTop: 'none',
47+
right: 0,
48+
width: 'auto',
49+
zIndex: 1,
50+
'&::before': {
51+
background: 'none',
52+
},
53+
},
54+
}),
55+
buttonsContainer: ({ euiTheme }: UseEuiTheme) =>
56+
css({
57+
margin: euiTheme.size.s,
58+
position: 'relative',
4359
}),
44-
buttonsContainer: css({
45-
position: 'relative',
46-
}),
4760
previewFooter: ({ euiTheme }: UseEuiTheme) =>
4861
css({
4962
opacity: 0,

0 commit comments

Comments
 (0)