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

Add horizontal resizability to autocomplete popup #180243

Merged

Conversation

sakurai-youhei
Copy link
Member

@sakurai-youhei sakurai-youhei commented Apr 7, 2024

Summary

This PR adds horizontal resizability to the autocomplete popup. The resized width does not persist, so it returns to the default on every load.

resizer

^^^ Demonstrated on Chrome Version 124.0.6367.91 (Official Build) (64-bit).

Appearance on Edge Version Version 124.0.2478.51 (Official build) (64-bit)

image
image

Appearance on Firefox 125.0.2 (64-bit)

image
image

Appearance on Safari 17.2.1 (19617.1.17.11.12)

Show scroll bars=Automatically
2024-04-26 19 10 24

Show scroll bars=Always
2024-04-26 19 11 02

Appearance on iOS Safari 17.4.1 - popup does not looks good same as before

vvvThis branch:
image

vvv8.13.0:
image

Appearances at 232897c

autocomplete-resizability-chrome-3
^^^ Demonstrated on Chrome Version 123.0.6312.123 (Official Build) (64-bit).

Appearance on Edge Version 123.0.2420.81 (Official build) (64-bit)

image
image

Appearance on Firefox 124.0.2 (64-bit)

image
image

Appearance on Safari 17.2.1 (19617.1.17.11.12)

image
image

Appearances at 98864be

autocomplete-resizability-2
^^^ Demonstrated on Chrome Version 123.0.6312.106 (Official Build) (64-bit).

Appearance on Edge Version 123.0.2420.81 (Official build) (64-bit)

autocomplete-resizability-edge-2

Appearance on Firefox 124.0.2 (64-bit)

autocomplete-resizability-firefox-2

Appearance on Safari 17.2.1 (19617.1.17.11.12)

image

Closes #171268
Closes #125186

Justification

The autocomplete popup width has been fixed to 280px HERE for a long time. Extending it would also be appreciated as ace 1.32.9 defaults it to 300px, and other projects using the ace make it even wider. However, this PR doesn't scope the extension because it's not easy to determine the best width. Furthermore, automatic fitting to suggestions' width is also excluded from the scope to avoid generating new corner cases.

A horizontal scrollbar is an alternative solution, but it's less cost-effective because it requires writing code to sync two separate DOM elements, .ace_scrollbar.ace_scrollbar-h and .ace_scroller.

For keyboard accessibility, it's definitely best to add two shortcuts, making the autocomplete popup wider and narrower. However, the questions are what key combinations are natural for them and what delta is appropriate per expansion/shrink. This could be addressed as another enhancement if key combinations were suggested at least.

CSS resizer on Safari

The CSS resizer behaves uniquely on Safari. You can't resize an element if another element overlaps the resizer like this.

data:text/html,<div%20style="position:fixed;width:280px;height:128px;resize:both;border:solid%201px;overflow:hidden;"><div%20style="position:absolute;right:0px;bottom:0px;">FOO<div></div>
Safari.17.2.1.2024-04-18.23.20.05.mov

The workaround is to set a negative z-index to the overlapping element like this.

data:text/html,<div%20style="position:fixed;width:280px;height:128px;resize:both;border:solid%201px;overflow:hidden;"><div%20style="position:absolute;right:0px;bottom:0px;z-index:-1;">FOO<div></div>

Checklist

For maintainers

Release note

Adds horizontal resizability to the autocomplete popup on the Dev Tools Console

@sakurai-youhei sakurai-youhei added release_note:enhancement Feature:Console Dev Tools Console Feature enhancement New value added to drive a business result labels Apr 7, 2024
@sakurai-youhei sakurai-youhei marked this pull request as ready for review April 7, 2024 16:12
@sakurai-youhei sakurai-youhei requested a review from a team as a code owner April 7, 2024 16:12
@MichaelMarcialis MichaelMarcialis requested a review from a team April 9, 2024 20:17
@ElenaStoeva ElenaStoeva self-requested a review April 12, 2024 15:56
Copy link
Contributor

@ElenaStoeva ElenaStoeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @sakurai-youhei. I tested locally and the resizability works well overall. However, I noticed a small visual regression - now the side bar covers the last letter of each word specifying the type of the suggestion:
Screenshot 2024-04-12 at 18 51 00
You can uncover them by extending the autocomplete popup to the right, but they are covered in the initial state when the popup appears and I don't think this looks good visually. Would there be any fix for this?

Also, please keep in mind that we are in the process of migrating Console to Monaco editor (see #180207) so we might need to implement this there as well once we complete the migration.

@sakurai-youhei
Copy link
Member Author

sakurai-youhei commented Apr 13, 2024

@ElenaStoeva Thank you for finding the regression. I didn't notice it because it didn't impact Chrome on my laptop. I've fixed it in the latest commit.

Regarding the new Console, noted and will try to implement it somehow through another PR Monaco Editor has built-in horizontal and vertical resizers that will be activated by one or more suggestions even in the new Console. The rest is definitely off-topic, but the following is a quick implementation of the suggestionProvider and how it looks.

Resize in new Console

src/plugins/console/public/application/containers/editor/monaco/monaco_editor.tsx at 672bb5a

/*
 * https://github.com/elastic/kibana/blob/main/packages/shared-ux/code_editor/impl/code_editor.tsx#L65-L70
 * https://microsoft.github.io/monaco-editor/docs.html#interfaces/languages.CompletionItemProvider.html
 * https://microsoft.github.io/monaco-editor/playground.html?source=v0.44.0#example-extending-language-services-completion-provider-example
 */
suggestionProvider={
  new (class implements monaco.languages.CompletionItemProvider {
    provideCompletionItems(model: monaco.editor.ITextModel, position: monaco.Position) {
      const word = model.getWordUntilPosition(position);
      const range = {
        startLineNumber: position.lineNumber,
        endLineNumber: position.lineNumber,
        startColumn: word.startColumn,
        endColumn: word.endColumn,
      };
      return {
        suggestions: Array(20).fill({
          label: '"test-label"',
          kind: monaco.languages.CompletionItemKind.Function,
          documentation: 'test documentation',
          insertText: '"test": "*"',
          range,
        }),
      };
    }
  })()
}

resize-in-new-console

Copy link
Contributor

@ElenaStoeva ElenaStoeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my feedback @sakurai-youhei! Tested again and now it looks good to me.

Regarding the new Console, Monaco Editor has built-in horizontal and vertical resizers that will be activated by one or more suggestions even in the new Console. The rest is definitely off-topic, but the following is a quick implementation of the suggestionProvider and how it looks.

Noted, thanks! We'll keep this in mind when we implement the autocomplete functionality in the Console Monaco editor. cc: @yuliacech

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sakurai-youhei! I've added some comments below for my initial review.

src/plugins/console/public/styles/_index.scss Outdated Show resolved Hide resolved
src/plugins/console/public/styles/_index.scss Outdated Show resolved Hide resolved
src/plugins/console/public/styles/_index.scss Outdated Show resolved Hide resolved
Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change and comments @sakurai-youhei. I've responded to your comments below. Assuming you're able to address those responses, I'll go ahead and approve this now to unblock you for feature freeze.

src/plugins/console/public/styles/_index.scss Outdated Show resolved Hide resolved
src/plugins/console/public/styles/_index.scss Outdated Show resolved Hide resolved
@sakurai-youhei
Copy link
Member Author

@MichaelMarcialis I changed how to expose the resizer on Safari and updated the PR description accordingly.

I believe the negative z-index doesn't create a new incompatibility because #151386 has already introduced it. But I know it doesn't mean zero concerns around this negative z-index trick. Although I've gone through browsers again, I appreciate your review & checks again. If you find this way is not preferable, please let me know, and I will try to find another.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
console 32.6KB 32.9KB +322.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@sakurai-youhei sakurai-youhei merged commit 0f375e3 into elastic:main Apr 27, 2024
18 checks passed
@kibanamachine kibanamachine added v8.15.0 backport:skip This commit does not require backporting labels Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting enhancement New value added to drive a business result Feature:Console Dev Tools Console Feature release_note:enhancement v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Field picker dropdown truncated [Console] Autocomplete window doesn't have enough space for long index names
5 participants