Skip to content

Commit a966e9f

Browse files
abidlabsgradio-pr-bothannahblair
authoredNov 12, 2024··
Hide upload button after upload when file_count="single" (#9946)
* format' * add changeset * add story --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Hannah <hannahblair@users.noreply.github.com>
1 parent ceb4005 commit a966e9f

File tree

4 files changed

+62
-37
lines changed

4 files changed

+62
-37
lines changed
 

‎.changeset/nice-rice-smash.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@gradio/file": patch
3+
"@gradio/multimodaltextbox": patch
4+
"gradio": patch
5+
---
6+
7+
fix:Hide upload button after upload when `file_count="single"`

‎js/file/shared/FileUpload.svelte

+17-15
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,23 @@
6161

6262
{#if value && (Array.isArray(value) ? value.length > 0 : true)}
6363
<IconButtonWrapper>
64-
<IconButton Icon={UploadIcon} label={i18n("common.upload")}>
65-
<Upload
66-
icon_upload={true}
67-
on:load={handle_upload}
68-
filetype={file_types}
69-
{file_count}
70-
{max_file_size}
71-
{root}
72-
bind:dragging
73-
bind:uploading
74-
on:error
75-
{stream_handler}
76-
{upload}
77-
/>
78-
</IconButton>
64+
{#if !(file_count === "single" && (Array.isArray(value) ? value.length > 0 : value !== null))}
65+
<IconButton Icon={UploadIcon} label={i18n("common.upload")}>
66+
<Upload
67+
icon_upload={true}
68+
on:load={handle_upload}
69+
filetype={file_types}
70+
{file_count}
71+
{max_file_size}
72+
{root}
73+
bind:dragging
74+
bind:uploading
75+
on:error
76+
{stream_handler}
77+
{upload}
78+
/>
79+
</IconButton>
80+
{/if}
7981
<IconButton
8082
Icon={Clear}
8183
label={i18n("common.clear")}

‎js/multimodaltextbox/MultimodalTextbox.stories.svelte

+14
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,17 @@
7373
/>
7474
<Story name="Right aligned textbox" args={{ text_align: "right" }} />
7575
<Story name="RTL textbox" args={{ rtl: true }} />
76+
<Story
77+
name="Single file upload"
78+
args={{
79+
file_count: "single",
80+
value: {
81+
text: "sample text",
82+
files: [
83+
{
84+
path: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg"
85+
}
86+
]
87+
}
88+
}}
89+
/>

‎js/multimodaltextbox/shared/MultimodalTextbox.svelte

+24-22
Original file line numberDiff line numberDiff line change
@@ -315,28 +315,30 @@
315315
</div>
316316
{/if}
317317
<div class="input-container">
318-
<Upload
319-
bind:this={upload_component}
320-
on:load={handle_upload}
321-
{file_count}
322-
filetype={file_types}
323-
{root}
324-
{max_file_size}
325-
bind:dragging
326-
bind:uploading
327-
show_progress={false}
328-
disable_click={true}
329-
bind:hidden_upload
330-
on:error
331-
hidden={true}
332-
{upload}
333-
{stream_handler}
334-
></Upload>
335-
<button
336-
data-testid="upload-button"
337-
class="upload-button"
338-
on:click={handle_upload_click}><Paperclip /></button
339-
>
318+
{#if !disabled && !(file_count === "single" && value.files.length > 0)}
319+
<Upload
320+
bind:this={upload_component}
321+
on:load={handle_upload}
322+
{file_count}
323+
filetype={file_types}
324+
{root}
325+
{max_file_size}
326+
bind:dragging
327+
bind:uploading
328+
show_progress={false}
329+
disable_click={true}
330+
bind:hidden_upload
331+
on:error
332+
hidden={true}
333+
{upload}
334+
{stream_handler}
335+
></Upload>
336+
<button
337+
data-testid="upload-button"
338+
class="upload-button"
339+
on:click={handle_upload_click}><Paperclip /></button
340+
>
341+
{/if}
340342
<textarea
341343
data-testid="textbox"
342344
use:text_area_resize={{

0 commit comments

Comments
 (0)
Please sign in to comment.