Skip to content

Commit

Permalink
[ES|QL] Give the ability to disable the autofocus on the editor (#204706
Browse files Browse the repository at this point in the history
)

## Summary

Right now, the editor autofocuses by default. But there are cases that a
consumer won't want this (autofocus might trigger the suggestions).

This PR introduces a new property which allows the consumers to disable
this feature.

(I need this for the ES|QL variables feature)
  • Loading branch information
stratoula authored Dec 19, 2024
1 parent 91e9995 commit 65437c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const ESQLEditor = memo(function ESQLEditor({
hideQueryHistory,
hasOutline,
displayDocumentationAsFlyout,
disableAutoFocus,
}: ESQLEditorProps) {
const popoverRef = useRef<HTMLDivElement>(null);
const datePickerOpenStatusRef = useRef<boolean>(false);
Expand Down Expand Up @@ -727,8 +728,10 @@ export const ESQLEditor = memo(function ESQLEditor({
editor.onDidChangeModelContent(showSuggestionsIfEmptyQuery);

// Auto-focus the editor and move the cursor to the end.
editor.focus();
editor.setPosition({ column: Infinity, lineNumber: Infinity });
if (!disableAutoFocus) {
editor.focus();
editor.setPosition({ column: Infinity, lineNumber: Infinity });
}
}}
/>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/platform/packages/private/kbn-esql-editor/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export interface ESQLEditorProps {

/** adds a documentation icon in the footer which opens the inline docs as a flyout **/
displayDocumentationAsFlyout?: boolean;

/** The component by default focuses on the editor when it is mounted, this flag disables it**/
disableAutoFocus?: boolean;
}

export interface ESQLEditorDeps {
Expand Down

0 comments on commit 65437c4

Please sign in to comment.