Fix text settings to be honored in Canvas markdown elements (#179948)

The `style` could be set in the legacy React `<Markdown>` component, so this change imitates it in the new shared ux markdown as well.
This commit is contained in:
Youhei Sakurai 2024-04-04 02:04:05 +09:00 committed by GitHub
parent c1d310bbc6
commit 43ecbcf5da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

View file

@ -11,6 +11,7 @@ date: 2022-10-03
This markdown component uses the **EuiMarkdownEditor** and **EuiMarkdownFormat** managed by `@elastic/eui`. If `readOnly` is set to true, and `markdownContent` or `children` are set, then the component renders **EuiMarkdownFormat** text. Otherwise the component will render the **EuiMarkdownEditor**. The height of the component can be set, but in order the control the width of the component, you can place the `<Markdown />` component in another component.
Markdown extends all the EuiMarkdownEditorProps except for the `editorId`, `uiPlugins`, and `MarkdownFormatProps`.
Like the legacy React `<Markdown>` component, `style` can be set but will only be passed to **EuiMarkdownFormat**.
## Component Properties

View file

@ -33,4 +33,16 @@ describe('shared ux markdown component', () => {
render(<Markdown markdownContent={exampleMarkdownContent} />);
expect(screen.getByTestId('euiMarkdownEditorToolbar')).toBeInTheDocument();
});
it('renders EuiMarkdownEditor without style passed', () => {
render(<Markdown style={{ color: 'red' }} data-test-subj="editor" />);
expect(screen.getByTestId('editor')).not.toHaveStyle({ color: 'red' });
});
it('renders EuiMarkdownFormat with style passed', () => {
render(
<Markdown style={{ color: 'red' }} data-test-subj="format" markdownContent="test" readOnly />
);
expect(screen.getByTestId('format')).toHaveStyle({ color: 'red' });
});
});

View file

@ -93,6 +93,8 @@ export const Markdown = ({
parsingPluginList={_parsingPlugins}
processingPluginList={openLinksInNewTab ? processingPlugins : undefined}
data-test-subj={restProps['data-test-subj']}
// There was a trick to pass style as a part of props in the legacy React <Markdown> component
style={restProps.style}
>
{children ?? markdownContent!}
</EuiMarkdownFormat>