mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-31 12:20:26 +08:00
detect all types of null default value (#1685)
* detect all types of null default value * fix test * address review comments
This commit is contained in:
parent
eb42fc3cf8
commit
a2b84199d8
@ -1233,9 +1233,7 @@ class Radio(Changeable, IOComponent):
|
||||
Returns:
|
||||
(str): string of choice
|
||||
"""
|
||||
return (
|
||||
y if y is not None else self.choices[0] if len(self.choices) > 0 else None
|
||||
)
|
||||
return y
|
||||
|
||||
def deserialize(self, x):
|
||||
"""
|
||||
|
@ -537,7 +537,7 @@ class TestRadio(unittest.TestCase):
|
||||
radio_input.get_config(),
|
||||
{
|
||||
"choices": ["a", "b", "c"],
|
||||
"value": "a",
|
||||
"value": None,
|
||||
"name": "radio",
|
||||
"show_label": True,
|
||||
"label": "Pick Your One Input",
|
||||
|
@ -119,12 +119,22 @@
|
||||
const is_input = is_dep(id, "inputs", dependencies);
|
||||
const is_output = is_dep(id, "outputs", dependencies);
|
||||
|
||||
if (!is_input && !is_output && !props.value) acc.add(id); // default dynamic
|
||||
if (!is_input && !is_output && has_no_default_value(props.value))
|
||||
acc.add(id); // default dynamic
|
||||
if (is_input) acc.add(id);
|
||||
|
||||
return acc;
|
||||
}, new Set());
|
||||
|
||||
function has_no_default_value(value: any) {
|
||||
return (
|
||||
(Array.isArray(value) && value.length === 0) ||
|
||||
value === "" ||
|
||||
value === 0 ||
|
||||
!value
|
||||
);
|
||||
}
|
||||
|
||||
let instance_map = components.reduce((acc, next) => {
|
||||
acc[next.id] = next;
|
||||
return acc;
|
||||
|
Loading…
x
Reference in New Issue
Block a user