Skip to content

Commit

Permalink
Dispatch dropdown change on value change for any reason (#4128)
Browse files Browse the repository at this point in the history
* changes

* changes

* changes

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
2 people authored and dawoodkhan82 committed May 12, 2023
1 parent dbb35c0 commit 2802c36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ No changes to highlight.
## New Features:

- Adds a `root_path` parameter to `launch()` that allows running Gradio applications on subpaths (e.g. www.example.com/app) behind a proxy, by [@abidlabs](https://github.com/abidlabs) in [PR 4133](https://github.com/gradio-app/gradio/pull/4133)
- Fix dropdown change listener to trigger on change when updated as an output by [@aliabid94](https://github.com/aliabid94) in [PR 4128](https://github.com/gradio-app/gradio/pull/4128).

## Bug Fixes:

Expand Down
23 changes: 8 additions & 15 deletions js/form/src/Dropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
export let label: string;
export let info: string | undefined = undefined;
export let value: string | Array<string> | undefined;
let old_value = Array.isArray(value) ? value.slice() : value;
export let multiselect: boolean = false;
export let max_choices: number;
export let choices: Array<string>;
Expand Down Expand Up @@ -46,7 +47,6 @@
value: option,
selected: true
});
dispatch("change", value);
}
value = value;
}
Expand All @@ -59,14 +59,12 @@
value: option,
selected: false
});
dispatch("change", value);
}
function remove_all(e: any) {
value = [];
inputValue = "";
e.preventDefault();
dispatch("change", value);
}
function handleOptionMousedown(e: any) {
Expand All @@ -92,7 +90,6 @@
value: option,
selected: true
});
dispatch("change", value);
return;
}
}
Expand All @@ -108,7 +105,6 @@
value: value,
selected: true
});
dispatch("change", value);
}
inputValue = activeOption;
showOptions = false;
Expand Down Expand Up @@ -148,6 +144,13 @@
}
}
}
$: {
if (JSON.stringify(value) != JSON.stringify(old_value)) {
dispatch("change", value);
old_value = Array.isArray(value) ? value.slice() : value;
}
}
</script>

<label>
Expand Down Expand Up @@ -190,14 +193,12 @@
on:keyup={() => {
if (allow_custom_value) {
value = inputValue;
dispatch("change", value);
}
}}
on:blur={() => {
if (multiselect) {
inputValue = "";
} else if (!allow_custom_value) {
let old_value = value;
if (value !== inputValue) {
if (typeof value === "string" && inputValue == "") {
inputValue = value;
Expand All @@ -206,9 +207,6 @@
inputValue = "";
}
}
if (old_value !== value) {
dispatch("change", value);
}
}
showOptions = false;
}}
Expand Down Expand Up @@ -294,11 +292,6 @@
height: 18px;
}
.single-select {
margin: var(--spacing-sm);
color: var(--body-text-color);
}
.secondary-wrap {
display: flex;
flex: 1 1 0%;
Expand Down

0 comments on commit 2802c36

Please sign in to comment.