diff --git a/packages/grafana-ui/src/components/Typeahead/TypeaheadInfo.test.tsx b/packages/grafana-ui/src/components/Typeahead/TypeaheadInfo.test.tsx new file mode 100644 index 00000000000..0864fa79b84 --- /dev/null +++ b/packages/grafana-ui/src/components/Typeahead/TypeaheadInfo.test.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import { TypeaheadInfo } from './TypeaheadInfo'; +import { CompletionItem } from '../../types'; + +describe('TypeaheadInfo component', () => { + it('should show documentation as rendered markdown if passed as a markdown', () => { + const item: CompletionItem = { label: 'markdown', documentation: '**bold**' }; + const wrapper = mount(); + expect(wrapper.find('div>div').html()).toMatch('strong'); + }); +}); diff --git a/packages/grafana-ui/src/components/Typeahead/TypeaheadInfo.tsx b/packages/grafana-ui/src/components/Typeahead/TypeaheadInfo.tsx index c6d66e99fd1..235b1007c91 100644 --- a/packages/grafana-ui/src/components/Typeahead/TypeaheadInfo.tsx +++ b/packages/grafana-ui/src/components/Typeahead/TypeaheadInfo.tsx @@ -2,7 +2,7 @@ import React, { useContext } from 'react'; import { css, cx } from 'emotion'; import { CompletionItem, selectThemeVariant, ThemeContext } from '../..'; -import { GrafanaTheme } from '@grafana/data'; +import { GrafanaTheme, renderMarkdown, textUtil } from '@grafana/data'; const getStyles = (theme: GrafanaTheme, height: number, visible: boolean) => { return { @@ -41,7 +41,7 @@ interface Props { export const TypeaheadInfo: React.FC = ({ item, height }) => { const visible = item && !!item.documentation; const label = item ? item.label : ''; - const documentation = item && item.documentation ? item.documentation : ''; + const documentation = textUtil.sanitize(renderMarkdown(item?.documentation)); const theme = useContext(ThemeContext); const styles = getStyles(theme, height, visible); @@ -49,7 +49,7 @@ export const TypeaheadInfo: React.FC = ({ item, height }) => {
{label}
- {documentation} +
); };