Skip to content

Commit

Permalink
Ensure dataframe is not editable when interactive is False (#10494)
Browse files Browse the repository at this point in the history
* fix editing logic

* add story

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
hannahblair and gradio-pr-bot authored Feb 4, 2025
1 parent ed7a091 commit 10932a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/tough-adults-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/dataframe": patch
"gradio": patch
---

feat:Ensure dataframe is not editable when `interactive` is False
20 changes: 20 additions & 0 deletions js/dataframe/Dataframe.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@
row_count: [3, "dynamic"],
editable: false
}}
play={async ({ canvasElement }) => {
// tests that the cell is not editable

const canvas = within(canvasElement);
const cells = canvas.getAllByRole("cell");
const initial_value = cells[0].textContent;

await userEvent.click(cells[0]);
await userEvent.keyboard("new value");

const final_value = cells[0].textContent;
if (initial_value !== final_value) {
throw new Error("Cell content changed when it should be non-editable");
}

const inputs = canvas.queryAllByRole("textbox");
if (inputs.length > 0) {
throw new Error("Input field appeared when table should be non-editable");
}
}}
/>

<Story
Expand Down
5 changes: 4 additions & 1 deletion js/dataframe/shared/Table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
selected_cells = handle_selection([row, col], selected_cells, event);
if (selected_cells.length === 1) {
if (selected_cells.length === 1 && editable) {
editing = [row, col];
tick().then(() => {
const input_el = els[data[row][col].id].input;
Expand Down Expand Up @@ -823,6 +823,7 @@
edit={false}
el={null}
{root}
{editable}
/>

<div
Expand Down Expand Up @@ -858,6 +859,7 @@
edit={false}
el={null}
{root}
{editable}
/>
</div>
</td>
Expand Down Expand Up @@ -923,6 +925,7 @@
on:dblclick={() => edit_header(i)}
header
{root}
{editable}
/>
<button
class:sorted={sort_by === i}
Expand Down

0 comments on commit 10932a2

Please sign in to comment.