Closed unkcpz closed 2 months ago
Just for the record, I asked the anywidget developers in Discords, and got the suggestion for such case it is better to implement from scratch.
import anywidget
import traitlets
class Dropdown(anywidget.AnyWidget):
_esm = """
function render({ model, el }) {
let options = model.get("options");
let value = model.get("value");
let select = document.createElement("select");
for (let [value, text] of options) {
let option = document.createElement("option");
option.value = value;
option.text = text;
select.appendChild(option);
}
if (value) {
select.value = value;
}
select.addEventListener("change", () => {
model.set("value", select.value);
model.save_changes();
})
model.on("change:value", () => {
select.value = model.get("value");
});
el.appendChild(select);
}
export default { render };
"""
value = traitlets.Unicode().tag(sync=True)
options = traitlets.List().tag(sync=True)
Codecov Report
Attention:
6 lines
in your changes are missing coverage. Please review.Additional details and impacted files
```diff @@ Coverage Diff @@ ## main #17 +/- ## ========================================== - Coverage 33.76% 33.76% -0.01% ========================================== Files 20 21 +1 Lines 2375 2387 +12 ========================================== + Hits 802 806 +4 - Misses 1573 1581 +8 ``` | [Flag](https://app.codecov.io/gh/aiidalab/ipyoptimade/pull/17/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidalab) | Coverage Δ | | |---|---|---| | [ipyoptimade-py-3.11](https://app.codecov.io/gh/aiidalab/ipyoptimade/pull/17/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidalab) | `33.76% <0.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidalab#carryforward-flags-in-the-pull-request-comment) to find out more.:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.