Skip to content

Commit 429faeb

Browse files
abidlabsclaudegradio-pr-bothysts
authored
Ensure every component dispatches a change event (#13502)
* Add change event to AnnotatedImage and native plots Issue #5309 asks that every value-bearing component dispatch a `change` event. AnnotatedImage and the native plots (BarPlot/LinePlot/ScatterPlot) were missing `.change()`. - AnnotatedImage: add Events.change to EVENTS. The frontend already dispatches change via gradio.watch_for_change() and declares it in its event types, so only the Python listener was missing. - NativePlot: add Events.change to EVENTS, call gradio.watch_for_change() in nativeplot/Index.svelte, and add `change` to NativePlotEvents. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * add changeset * Add change event to remaining value components (buttons, Dataset, Timer, WorkflowCanvas) Every component has a programmatically-settable `value` (a Button's value is its label), so per #5309 every component should dispatch `change` when that value changes. This completes the audit: no component is left without `change`. - Button (and ClearButton/DuplicateButton/LoginButton/DeepLinkButton, which render via the button frontend), DownloadButton, UploadButton, Dataset, Timer, WorkflowCanvas: add Events.change to EVENTS. - Wire gradio.watch_for_change() in the corresponding Index.svelte files and declare `change` in their event type interfaces. watch_for_change() only dispatches when props.value actually differs, so it is added only to components that did not already manually dispatch change (no double-firing for the ~30 components that handle change themselves). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Update changeset for full change-event coverage Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Add test that every component has a working .change() event - test/test_components.py: test_all_components_have_change_event iterates all core Component subclasses, asserts each has a `change` event and that wiring `.change()` inside a Blocks context does not error. - Fallback also gets Events.change + watch_for_change() so the invariant holds for every component (its event types already declared `change`). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Fix UploadButton double change-firing, simplify test, regen skill docs - UploadButton already dispatches `change` on upload, so the added watch_for_change() made the change event fire twice (broke the js-test "upload and change events fire after file upload"). Remove it. - test_all_components_have_change_event: use the io_components fixture and a single `component().change(lambda: None)` check (addresses review feedback). - Regenerate references/event-listeners.md via scripts/generate_skill.py to reflect the new change events (fixes hygiene-test). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Update js/button/Index.svelte Co-authored-by: hysts <[email protected]> * changes --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: hysts <[email protected]>
1 parent a9550d8 commit 429faeb

23 files changed

Lines changed: 67 additions & 22 deletions

File tree

‎.agents/skills/gradio/references/event-listeners.md‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,43 @@ component.event_name(
3535

3636
## Supported Events by Component
3737

38-
- **AnnotatedImage**: select
38+
- **AnnotatedImage**: change, select
3939

4040
- **Audio**: stream, change, clear, play, pause, stop, pause, start_recording, pause_recording, stop_recording, upload, input
4141

42-
- **BarPlot**: select, double_click
42+
- **BarPlot**: change, select, double_click
4343

4444
- **BrowserState**: change
4545

46-
- **Button**: click
46+
- **Button**: change, click
4747

4848
- **Chatbot**: change, select, like, retry, undo, example_select, option_select, clear, copy, edit
4949

5050
- **Checkbox**: change, input, select
5151

5252
- **CheckboxGroup**: change, input, select
5353

54-
- **ClearButton**: click
54+
- **ClearButton**: change, click
5555

5656
- **Code**: change, input, focus, blur
5757

5858
- **ColorPicker**: change, input, release, submit, focus, blur
5959

6060
- **Dataframe**: change, input, select, edit
6161

62-
- **Dataset**: click, select
62+
- **Dataset**: change, click, select
6363

6464
- **DateTime**: change, submit
6565

66-
- **DeepLinkButton**: click
66+
- **DeepLinkButton**: change, click
6767

6868
- **Dialogue**: change, input, submit
6969

70-
- **DownloadButton**: click
70+
- **DownloadButton**: change, click
7171

7272
- **Dropdown**: change, input, select, focus, blur, key_up
7373

74-
- **DuplicateButton**: click
74+
- **DuplicateButton**: change, click
7575

7676
- **File**: change, select, clear, upload, delete, download
7777

@@ -93,9 +93,9 @@ component.event_name(
9393

9494
- **Label**: change, select
9595

96-
- **LinePlot**: select, double_click
96+
- **LinePlot**: change, select, double_click
9797

98-
- **LoginButton**: click
98+
- **LoginButton**: change, click
9999

100100
- **Markdown**: change, copy
101101

@@ -113,7 +113,7 @@ component.event_name(
113113

114114
- **Radio**: select, change, input
115115

116-
- **ScatterPlot**: select, double_click
116+
- **ScatterPlot**: change, select, double_click
117117

118118
- **SimpleImage**: clear, change, upload
119119

@@ -123,8 +123,10 @@ component.event_name(
123123

124124
- **Textbox**: change, input, select, submit, focus, blur, stop, copy
125125

126-
- **Timer**: tick
126+
- **Timer**: change, tick
127127

128-
- **UploadButton**: click, upload
128+
- **UploadButton**: change, click, upload
129129

130130
- **Video**: change, clear, start_recording, stop_recording, stop, play, pause, end, upload, input
131+
132+
- **WorkflowCanvas**: change

‎.changeset/odd-zebras-fry.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@gradio/button": minor
3+
"@gradio/dataset": minor
4+
"@gradio/downloadbutton": minor
5+
"@gradio/fallback": minor
6+
"@gradio/nativeplot": minor
7+
"@gradio/timer": minor
8+
"@gradio/uploadbutton": minor
9+
"@gradio/workflowcanvas": minor
10+
"gradio": minor
11+
---
12+
13+
feat:Ensure every component dispatches a `change` event when its value changes

‎gradio/components/annotated_image.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class AnnotatedImage(Component):
4444
Demos: image_segmentation
4545
"""
4646

47-
EVENTS = [Events.select]
47+
EVENTS = [Events.change, Events.select]
4848

4949
data_model = AnnotatedImageData
5050

‎gradio/components/button.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Button(Component):
2222
Creates a button that can be assigned arbitrary .click() events. The value (label) of the button can be used as an input to the function (rarely used) or set via the output of a function.
2323
"""
2424

25-
EVENTS = [Events.click]
25+
EVENTS = [Events.change, Events.click]
2626

2727
def __init__(
2828
self,

‎gradio/components/dataset.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Dataset(Component):
2424
However, it can also be used directly to display a dataset and let users select examples.
2525
"""
2626

27-
EVENTS = [Events.click, Events.select]
27+
EVENTS = [Events.change, Events.click, Events.select]
2828

2929
def __init__(
3030
self,

‎gradio/components/download_button.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DownloadButton(Component):
2626
Demos: upload_and_download
2727
"""
2828

29-
EVENTS = [Events.click]
29+
EVENTS = [Events.change, Events.click]
3030

3131
def __init__(
3232
self,

‎gradio/components/fallback.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from gradio.components.base import Component
2+
from gradio.events import Events
23

34

45
class Fallback(Component):
6+
EVENTS = [Events.change]
7+
58
def preprocess(self, payload):
69
"""
710
This docstring is used to generate the docs for this custom component.

‎gradio/components/native_plot.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class NativePlot(Component):
3737
Demos: native_plots
3838
"""
3939

40-
EVENTS = [Events.select, Events.double_click]
40+
EVENTS = [Events.change, Events.select, Events.double_click]
4141

4242
def __init__(
4343
self,

‎gradio/components/timer.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Timer(Component):
2222
"""
2323

2424
EVENTS = [
25+
Events.change,
2526
Events.tick,
2627
]
2728

‎gradio/components/upload_button.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class UploadButton(Component):
3232
Demos: upload_and_download, upload_button
3333
"""
3434

35-
EVENTS = [Events.click, Events.upload]
35+
EVENTS = [Events.change, Events.click, Events.upload]
3636

3737
def __init__(
3838
self,

0 commit comments

Comments
 (0)