Skip to content

Commit a2b8419

Browse files
authored
detect all types of null default value (#1685)
* detect all types of null default value * fix test * address review comments
1 parent eb42fc3 commit a2b8419

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

gradio/components.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1233,9 +1233,7 @@ def postprocess(self, y):
12331233
Returns:
12341234
(str): string of choice
12351235
"""
1236-
return (
1237-
y if y is not None else self.choices[0] if len(self.choices) > 0 else None
1238-
)
1236+
return y
12391237

12401238
def deserialize(self, x):
12411239
"""

test/test_components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def test_component_functions(self):
537537
radio_input.get_config(),
538538
{
539539
"choices": ["a", "b", "c"],
540-
"value": "a",
540+
"value": None,
541541
"name": "radio",
542542
"show_label": True,
543543
"label": "Pick Your One Input",

ui/packages/app/src/Blocks.svelte

+11-1
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,22 @@
119119
const is_input = is_dep(id, "inputs", dependencies);
120120
const is_output = is_dep(id, "outputs", dependencies);
121121
122-
if (!is_input && !is_output && !props.value) acc.add(id); // default dynamic
122+
if (!is_input && !is_output && has_no_default_value(props.value))
123+
acc.add(id); // default dynamic
123124
if (is_input) acc.add(id);
124125
125126
return acc;
126127
}, new Set());
127128
129+
function has_no_default_value(value: any) {
130+
return (
131+
(Array.isArray(value) && value.length === 0) ||
132+
value === "" ||
133+
value === 0 ||
134+
!value
135+
);
136+
}
137+
128138
let instance_map = components.reduce((acc, next) => {
129139
acc[next.id] = next;
130140
return acc;

0 commit comments

Comments
 (0)