Skip to content

Commit 2700d18

Browse files
Ensure the height param in gr.File works as expected (#10209)
* * 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]>
1 parent 314a8b5 commit 2700d18

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

.changeset/major-walls-mix.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@gradio/file": patch
3+
"@gradio/upload": patch
4+
"gradio": patch
5+
---
6+
7+
fix:Ensure the `height` param in `gr.File` works as expected

gradio/components/file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
container: bool = True,
5555
scale: int | None = None,
5656
min_width: int = 160,
57-
height: int | float | None = None,
57+
height: int | str | float | None = None,
5858
interactive: bool | None = None,
5959
visible: bool = True,
6060
elem_id: str | None = None,

js/file/File.stories.svelte

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script>
22
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
3-
import FilePreview from "./shared/FilePreview.svelte";
3+
import File from "./Index.svelte";
44
</script>
55

66
<Meta
77
title="Components/File"
8-
component={FilePreview}
8+
component={File}
99
argTypes={{
1010
value: {
1111
control: "text",
@@ -17,7 +17,7 @@
1717
/>
1818

1919
<Template let:args>
20-
<FilePreview {...args} />
20+
<File {...args} />
2121
</Template>
2222

2323
<Story
@@ -54,3 +54,11 @@
5454
allow_reordering: true
5555
}}
5656
/>
57+
<Story
58+
name="File upload with height set to 400px"
59+
args={{
60+
interactive: true,
61+
value: null,
62+
height: 400
63+
}}
64+
/>

js/file/shared/FilePreview.svelte

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}>();
1414
export let value: FileData | FileData[];
1515
export let selectable = false;
16-
export let height: number | undefined = undefined;
16+
export let height: number | string | undefined = undefined;
1717
export let i18n: I18nFormatter;
1818
export let allow_reordering = false;
1919
@@ -124,7 +124,11 @@
124124

125125
<div
126126
class="file-preview-holder"
127-
style="max-height: {typeof height === undefined ? 'auto' : height + 'px'};"
127+
style:max-height={height
128+
? typeof height === "number"
129+
? height + "px"
130+
: height
131+
: "auto"}
128132
>
129133
<table class="file-preview">
130134
<tbody>

js/file/shared/FileUpload.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
on:error
113113
{stream_handler}
114114
{upload}
115+
{height}
115116
>
116117
<slot />
117118
</Upload>

js/upload/src/Upload.svelte

+15-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
export let upload: Client["upload"];
2323
export let stream_handler: Client["stream"];
2424
export let icon_upload = false;
25+
export let height: number | string | undefined = undefined;
2526
2627
let upload_id: string;
2728
let file_data: FileData[];
@@ -267,7 +268,13 @@
267268
class:boundedheight
268269
class:flex
269270
class:icon-mode={icon_upload}
270-
style:height={icon_upload ? "" : "100%"}
271+
style:height={icon_upload
272+
? ""
273+
: height
274+
? typeof height === "number"
275+
? height + "px"
276+
: height
277+
: "100%"}
271278
tabindex={hidden ? -1 : 0}
272279
on:click={paste_clipboard}
273280
>
@@ -285,7 +292,13 @@
285292
class:flex
286293
class:disable_click
287294
class:icon-mode={icon_upload}
288-
style:height={icon_upload ? "" : "100%"}
295+
style:height={icon_upload
296+
? ""
297+
: height
298+
? typeof height === "number"
299+
? height + "px"
300+
: height
301+
: "100%"}
289302
tabindex={hidden ? -1 : 0}
290303
on:drag|preventDefault|stopPropagation
291304
on:dragstart|preventDefault|stopPropagation

0 commit comments

Comments
 (0)