Skip to content

Automatically reposition InlineAutocomplete suggestions depending on available space #3614

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

Merged
merged 9 commits into from
Aug 14, 2023

Conversation

iansan5653
Copy link
Contributor

@iansan5653 iansan5653 commented Aug 9, 2023

InlineAutocomplete currently naively always places suggestions below the trigger character. This can cause the list to overflow the bottom edge of the screen.

The simple (and only slightly less naive) solution is to just put the suggestions on top if there's not enough space below. This is not an attempt to solve for every situation - the list can still overflow to the left, right, or top (if there's not enough vertical space above). And it won't automatically reposition on scroll. But it still solves for the vast majority of cases at very minimal performance cost.

Here's a Storybook demo that places the textarea at the bottom of the screen.

Screen.Recording.2023-08-09.at.4.03.38.PM.mov

@iansan5653 iansan5653 requested review from a team and langermank August 9, 2023 20:03
@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2023

🦋 Changeset detected

Latest commit: b5c2beb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 103.81 KB (+0.15% 🔺)
dist/browser.umd.js 104.37 KB (+0.14% 🔺)

@github-actions github-actions bot temporarily deployed to storybook-preview-3614 August 9, 2023 20:11 Inactive
@iansan5653 iansan5653 temporarily deployed to github-pages August 9, 2023 20:14 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3614 August 9, 2023 20:14 Inactive
@iansan5653 iansan5653 temporarily deployed to github-pages August 9, 2023 21:05 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3614 August 9, 2023 21:05 Inactive
@iansan5653 iansan5653 temporarily deployed to github-pages August 9, 2023 21:23 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3614 August 9, 2023 21:23 Inactive
@paxos
Copy link
Contributor

paxos commented Aug 10, 2023

This is great 👍

I think it would be even better if we could specify an anchor point on top of that. In the demo video you posted, you see the position twitching around if there is only one auto complete item (that does it).
By specifying an anchor direction, we could avoid that (e.g. things would float always above the cursor).

@iansan5653 iansan5653 temporarily deployed to github-pages August 10, 2023 18:55 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3614 August 10, 2023 18:56 Inactive
@langermank langermank requested review from joshblack and removed request for langermank August 11, 2023 16:31
Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

The changes are scoped inside drafts/InlineAutocomplete

I trust your judgement with the changes :)

* the suggestions will appear in the other direction.
* @default "belo"
*/
suggestionsPlacement?: SuggestionsPlacement
Copy link
Member

@siddharthkp siddharthkp Aug 14, 2023

Choose a reason for hiding this comment

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

(Not blocking suggestion) Should we lock to the suggestion if it's given? For example, If we start at "above", stick to above even when the list becomes smaller and there is now enough space below. Layout shift when filtering could be a bad user experience.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 IMHO it should be sticky

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that works for if the list becomes shorter while it's open, but not if the list becomes larger. If we try to distinguish between those cases, the logic becomes pretty challenging and I don't know if it's worth it considering how uncommon that will actually be in practice.

I tested in VSCode just now and the suggestions list can flip as you type. I've personally never noticed that before, so I think that this is probably not a very common case.

Co-authored-by: Josh Black <joshblack@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[InlineAutocomplete] Support showing suggestions list above the insertion point
4 participants