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
Dropdown cutoff fix #4691
Merged
Merged
Dropdown cutoff fix #4691
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
435fbde
form
abidlabs 774fcc4
changelog
abidlabs 5da1d4e
Merge branch 'main' into dropdown-fix
abidlabs 37d6729
overflow y
abidlabs 1b56236
Merge branch 'dropdown-fix' of github.com:gradio-app/gradio into drop…
abidlabs 2049edf
Merge branch 'main' into dropdown-fix
abidlabs cb8dd45
changes
aliabid94 37b7727
changes
aliabid94 5e9c39a
Merge branch 'main' into dropdown-fix
aliabid94 a1f8841
changes
aliabid94 f55d00a
Merge branch 'dropdown-fix' of https://github.com/gradio-app/gradio i…
aliabid94 61a1a0a
Update js/form/src/DropdownOptions.svelte
aliabid94 a91001e
Update js/form/src/DropdownOptions.svelte
aliabid94 d59c63a
changes
aliabid94 6b37600
changes
aliabid94 96f0add
Merge branch 'main' into dropdown-fix
aliabid94 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,32 @@ | |
let distance_from_top: number; | ||
let distance_from_bottom: number; | ||
let input_height: number; | ||
let input_width: number; | ||
let refElement: HTMLDivElement; | ||
let listElement: HTMLUListElement; | ||
let top: string | null, bottom: string | null, max_height: number; | ||
let innerHeight: number; | ||
|
||
const calculate_window_distance = () => { | ||
const { top: ref_top, bottom: ref_bottom } = | ||
refElement.getBoundingClientRect(); | ||
distance_from_top = ref_top; | ||
distance_from_bottom = innerHeight - ref_bottom; | ||
}; | ||
|
||
let scroll_timeout: NodeJS.Timeout | null = null; | ||
const scroll_listener = () => { | ||
if (!showOptions) return; | ||
if (scroll_timeout !== null) { | ||
clearTimeout(scroll_timeout); | ||
} | ||
|
||
scroll_timeout = setTimeout(() => { | ||
calculate_window_distance(); | ||
scroll_timeout = null; | ||
}, 10); | ||
}; | ||
|
||
$: { | ||
if (showOptions && refElement) { | ||
if (listElement && typeof value === "string") { | ||
|
@@ -23,18 +46,17 @@ | |
listElement.scrollTo(0, el.offsetTop); | ||
} | ||
} | ||
distance_from_top = refElement.getBoundingClientRect().top; | ||
distance_from_bottom = | ||
window.innerHeight - refElement.getBoundingClientRect().bottom; | ||
input_height = | ||
refElement.parentElement?.getBoundingClientRect().height || 0; | ||
calculate_window_distance(); | ||
const rect = refElement.parentElement?.getBoundingClientRect(); | ||
input_height = rect?.height || 0; | ||
input_width = rect?.width || 0; | ||
} | ||
if (distance_from_bottom > distance_from_top) { | ||
top = `${input_height}px`; | ||
top = `${distance_from_top}px`; | ||
max_height = distance_from_bottom; | ||
bottom = null; | ||
} else { | ||
bottom = `${input_height}px`; | ||
bottom = `${distance_from_bottom + input_height}px`; | ||
max_height = distance_from_top - input_height; | ||
top = null; | ||
Comment on lines
-37
to
61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently this is the only branch that is triggering because |
||
} | ||
|
@@ -44,6 +66,8 @@ | |
$: _value = Array.isArray(value) ? value : [value]; | ||
</script> | ||
|
||
<svelte:window on:scroll={scroll_listener} bind:innerHeight /> | ||
|
||
<div class="reference" bind:this={refElement} /> | ||
{#if showOptions && !disabled} | ||
<ul | ||
|
@@ -54,6 +78,7 @@ | |
style:top | ||
style:bottom | ||
style:max-height={`calc(${max_height}px - var(--window-padding))`} | ||
style:width={input_width + "px"} | ||
bind:this={listElement} | ||
> | ||
{#each filtered as choice} | ||
|
@@ -79,13 +104,12 @@ | |
<style> | ||
.options { | ||
--window-padding: var(--size-8); | ||
position: absolute; | ||
position: fixed; | ||
z-index: var(--layer-top); | ||
margin-left: 0; | ||
box-shadow: var(--shadow-drop-lg); | ||
border-radius: var(--container-radius); | ||
background: var(--background-fill-primary); | ||
width: var(--size-full); | ||
min-width: fit-content; | ||
max-width: inherit; | ||
overflow: auto; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
overflow-y
also work? Seems like it would be a more targeted fix if soThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change