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

fix autocomplete popover styles #2910

Merged
merged 1 commit into from
Nov 15, 2022
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
5 changes: 5 additions & 0 deletions .changeset/fresh-readers-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/react': patch
---

Fix autocomplete styles for field type and description on the right
27 changes: 19 additions & 8 deletions packages/graphiql-react/src/editor/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,19 @@ export function onHasCompletion(
* is already positioned absolutely.
*
* There are two things to the solution here:
* - We add another `overflow: auto` to the `information` element.
* This makes it scrollable on its own if the description or
* deprecation reason is higher that the container element.
* - We add a `max-height` and another `overflow: auto` to the
* `information` element. This makes it scrollable on its own
* if the description or deprecation reason is higher that the
* container element.
* - We add an `onscroll` handler to the container element. When the
* user scrolls here we dynamically adjust the top padding of the
* information element such that it looks like it's sticking to
* the top. (Since the `information` element has some padding by
* default we also have to make sure to use this as baseline for
* the total padding.)
* user scrolls here we dynamically adjust the top padding and the
* max-height of the information element such that it looks like
* it's sticking to the top. (Since the `information` element has
* some padding by default we also have to make sure to use this
* as baseline for the total padding.)
* Note that we need to also adjust the max-height because we
* default to using `border-box` for box sizing. When using
* `content-box` this would not be necessary.
*/
const defaultInformationPadding =
parseInt(
Expand All @@ -136,10 +140,17 @@ export function onHasCompletion(
.paddingBottom.replace(/px$/, ''),
10,
) || 0;
const defaultInformationMaxHeight =
parseInt(
window.getComputedStyle(information).maxHeight.replace(/px$/, ''),
10,
) || 0;
const handleScroll = () => {
if (information) {
information.style.paddingTop =
hintsUl.scrollTop + defaultInformationPadding + 'px';
information.style.maxHeight =
hintsUl.scrollTop + defaultInformationMaxHeight + 'px';
}
};
hintsUl.addEventListener('scroll', handleScroll);
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-react/src/editor/style/hint.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ li.CodeMirror-hint-active {
hsla(var(--color-neutral), var(--alpha-background-heavy));
grid-column: 2 / 3;
grid-row: 1 / 99999;
/* Same as the popup as a whole minus padding */
max-height: calc(264px - 2 * var(--px-12));
/* Same as the popup */
max-height: 264px;
overflow: auto;
padding: var(--px-12);
}
Expand Down