Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES|QL] Clicking the editor closes the documentation popover #176394

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
*/
import React, { useCallback, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiPopover, EuiToolTip, EuiButtonIcon, EuiButtonIconProps } from '@elastic/eui';
import {
EuiPopover,
EuiToolTip,
EuiButtonIcon,
EuiButtonIconProps,
EuiOutsideClickDetector,
} from '@elastic/eui';
import {
type LanguageDocumentationSections,
LanguageDocumentationPopoverContent,
Expand All @@ -33,35 +39,41 @@ function DocumentationPopover({
}, [isHelpOpen]);

return (
<EuiPopover
panelClassName="documentation__docs--overlay"
panelPaddingSize="none"
isOpen={isHelpOpen}
closePopover={() => setIsHelpOpen(false)}
button={
<EuiToolTip
position="top"
content={i18n.translate('languageDocumentationPopover.tooltip', {
defaultMessage: '{lang} reference',
values: {
lang: language,
},
})}
>
<EuiButtonIcon
iconType="documentation"
onClick={toggleDocumentationPopover}
{...buttonProps}
/>
</EuiToolTip>
}
<EuiOutsideClickDetector
onOutsideClick={() => {
setIsHelpOpen(false);
}}
>
<LanguageDocumentationPopoverContent
language={language}
sections={sections}
searchInDescription={searchInDescription}
/>
</EuiPopover>
<EuiPopover
panelClassName="documentation__docs--overlay"
panelPaddingSize="none"
isOpen={isHelpOpen}
closePopover={() => setIsHelpOpen(false)}
button={
<EuiToolTip
position="top"
content={i18n.translate('languageDocumentationPopover.tooltip', {
defaultMessage: '{lang} reference',
values: {
lang: language,
},
})}
>
<EuiButtonIcon
iconType="documentation"
onClick={toggleDocumentationPopover}
{...buttonProps}
/>
</EuiToolTip>
}
>
<LanguageDocumentationPopoverContent
language={language}
sections={sections}
searchInDescription={searchInDescription}
/>
</EuiPopover>
</EuiOutsideClickDetector>
);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-text-based-editor/src/text_based_languages_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,17 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
}
});

// this is fixing a bug between the EUIPopover and the monaco editor
// when the user clicks the editor, we force it to focus and the onDidFocusEditorText
// to fire, the timeout is needed because otherwise it refocuses on the popover icon
// and the user needs to click again the editor.
// IMPORTANT: The popover needs to be wrapped with the EuiOutsideClickDetector component.
editor.onMouseDown(() => {
setTimeout(() => {
editor.focus();
}, 100);
});

editor.onDidFocusEditorText(() => {
onEditorFocus();
});
Expand Down