Improve select event behaviour in gr.Dataframe (#9654)

* add last_selected prop

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Dawood Khan <dawoodkhan82@gmail.com>
This commit is contained in:
Hannah 2024-10-17 19:12:01 +01:00 committed by GitHub
parent 2735e89cd8
commit cd7dab7ba5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 5 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/dataframe": patch
"gradio": patch
---
fix:Improve select event behaviour in gr.Dataframe

View File

@ -56,8 +56,10 @@
const get_data_at = (row: number, col: number): string | number =>
data?.[row]?.[col]?.value;
let last_selected: [number, number] | null = null;
$: {
if (selected !== false) {
if (selected !== false && !dequal(selected, last_selected)) {
const [row, col] = selected;
if (!isNaN(row) && !isNaN(col) && data[row]) {
dispatch("select", {
@ -65,6 +67,7 @@
value: get_data_at(row, col),
row_value: data[row].map((d) => d.value)
});
last_selected = selected;
}
}
}
@ -353,9 +356,11 @@
header_edit = false;
selected_header = false;
editing = false;
selected = [i, j];
await tick();
parent.focus();
if (!dequal(selected, [i, j])) {
selected = [i, j];
await tick();
parent.focus();
}
}
type SortDirection = "asc" | "des";
@ -478,7 +483,7 @@
editing = false;
header_edit = false;
selected_header = false;
selected = false;
reset_selection();
active_cell = null;
active_cell_menu = null;
active_header_menu = null;
@ -760,6 +765,11 @@
}
}
}
function reset_selection(): void {
selected = false;
last_selected = null;
}
</script>
<svelte:window