mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-23 11:39:17 +08:00
fix: prevent triggering gr.File.select on delete (#8334)
* fix: prevent triggering gr.File.select on delete * extract into named function * go away eslint * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
4d78f29666
commit
0236b1ab12
6
.changeset/light-rats-exist.md
Normal file
6
.changeset/light-rats-exist.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gradio/file": patch
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:fix: prevent triggering gr.File.select on delete
|
@ -31,6 +31,20 @@
|
||||
};
|
||||
});
|
||||
|
||||
function handle_row_click(
|
||||
event: MouseEvent & { currentTarget: HTMLTableRowElement },
|
||||
index: number
|
||||
): void {
|
||||
const tr = event.currentTarget;
|
||||
const should_select =
|
||||
event.target === tr || // Only select if the click is on the row itself
|
||||
event.composedPath().includes(tr.firstElementChild); // Or if the click is on the name column
|
||||
|
||||
if (should_select) {
|
||||
dispatch("select", { value: normalized_files[index], index });
|
||||
}
|
||||
}
|
||||
|
||||
function remove_file(index: number): void {
|
||||
normalized_files.splice(index, 1);
|
||||
normalized_files = [...normalized_files];
|
||||
@ -45,15 +59,13 @@
|
||||
>
|
||||
<table class="file-preview">
|
||||
<tbody>
|
||||
{#each normalized_files as file, i}
|
||||
{#each normalized_files as file, i (file)}
|
||||
<tr
|
||||
class="file"
|
||||
class:selectable
|
||||
on:click={() =>
|
||||
dispatch("select", {
|
||||
value: file.orig_name,
|
||||
index: i
|
||||
})}
|
||||
on:click={(event) => {
|
||||
handle_row_click(event, i);
|
||||
}}
|
||||
>
|
||||
<td class="filename" aria-label={file.orig_name}>
|
||||
<span class="stem">{file.filename_stem}</span>
|
||||
@ -74,12 +86,15 @@
|
||||
{i18n("file.uploading")}
|
||||
{/if}
|
||||
</td>
|
||||
|
||||
{#if normalized_files.length > 1}
|
||||
<td>
|
||||
<button
|
||||
class="label-clear-button"
|
||||
aria-label="Remove this file"
|
||||
on:click={() => remove_file(i)}
|
||||
on:click={() => {
|
||||
remove_file(i);
|
||||
}}
|
||||
on:keydown={(event) => {
|
||||
if (event.key === "Enter") {
|
||||
remove_file(i);
|
||||
|
Loading…
Reference in New Issue
Block a user