Skip to content

Commit

Permalink
Ensure the height param in gr.File works as expected (#10209)
Browse files Browse the repository at this point in the history
* * allow height as string in gr.file
* change max-height to height

* add changeset

* * revert file preview height change
* apply height param in upload

* add changeset

* add story

---------

Co-authored-by: gradio-pr-bot <[email protected]>
  • Loading branch information
hannahblair and gradio-pr-bot authored Dec 17, 2024
1 parent 314a8b5 commit 2700d18
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changeset/major-walls-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@gradio/file": patch
"@gradio/upload": patch
"gradio": patch
---

fix:Ensure the `height` param in `gr.File` works as expected
2 changes: 1 addition & 1 deletion gradio/components/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(
container: bool = True,
scale: int | None = None,
min_width: int = 160,
height: int | float | None = None,
height: int | str | float | None = None,
interactive: bool | None = None,
visible: bool = True,
elem_id: str | None = None,
Expand Down
14 changes: 11 additions & 3 deletions js/file/File.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
import FilePreview from "./shared/FilePreview.svelte";
import File from "./Index.svelte";
</script>

<Meta
title="Components/File"
component={FilePreview}
component={File}
argTypes={{
value: {
control: "text",
Expand All @@ -17,7 +17,7 @@
/>

<Template let:args>
<FilePreview {...args} />
<File {...args} />
</Template>

<Story
Expand Down Expand Up @@ -54,3 +54,11 @@
allow_reordering: true
}}
/>
<Story
name="File upload with height set to 400px"
args={{
interactive: true,
value: null,
height: 400
}}
/>
8 changes: 6 additions & 2 deletions js/file/shared/FilePreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}>();
export let value: FileData | FileData[];
export let selectable = false;
export let height: number | undefined = undefined;
export let height: number | string | undefined = undefined;
export let i18n: I18nFormatter;
export let allow_reordering = false;
Expand Down Expand Up @@ -124,7 +124,11 @@

<div
class="file-preview-holder"
style="max-height: {typeof height === undefined ? 'auto' : height + 'px'};"
style:max-height={height
? typeof height === "number"
? height + "px"
: height
: "auto"}
>
<table class="file-preview">
<tbody>
Expand Down
1 change: 1 addition & 0 deletions js/file/shared/FileUpload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
on:error
{stream_handler}
{upload}
{height}
>
<slot />
</Upload>
Expand Down
17 changes: 15 additions & 2 deletions js/upload/src/Upload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
export let upload: Client["upload"];
export let stream_handler: Client["stream"];
export let icon_upload = false;
export let height: number | string | undefined = undefined;
let upload_id: string;
let file_data: FileData[];
Expand Down Expand Up @@ -267,7 +268,13 @@
class:boundedheight
class:flex
class:icon-mode={icon_upload}
style:height={icon_upload ? "" : "100%"}
style:height={icon_upload
? ""
: height
? typeof height === "number"
? height + "px"
: height
: "100%"}
tabindex={hidden ? -1 : 0}
on:click={paste_clipboard}
>
Expand All @@ -285,7 +292,13 @@
class:flex
class:disable_click
class:icon-mode={icon_upload}
style:height={icon_upload ? "" : "100%"}
style:height={icon_upload
? ""
: height
? typeof height === "number"
? height + "px"
: height
: "100%"}
tabindex={hidden ? -1 : 0}
on:drag|preventDefault|stopPropagation
on:dragstart|preventDefault|stopPropagation
Expand Down

0 comments on commit 2700d18

Please sign in to comment.