Public
Edited
Jul 5, 2024
Insert cell
Insert cell
function set(input, value) {
input.value = value;
input.dispatchEvent(new Event("input", { bubbles: true })); // Native events bubble, so we should too
}
Insert cell
Insert cell
Insert cell
DataListInput = (options, { label = "Select an option", value = "" } = {}) => {
const input = htl.html`
<input list="options" placeholder="${label}">
`;
const datalist = htl.html`
<datalist id="options">
${options.map(option => htl.html`<option value="${option}">`)}
</datalist>
`;
const node = htl.html`
<div>
${input}
${datalist}
</div>
`;

// Update the display whenever the value changes
Object.defineProperty(node, "value", {
get() {
return value;
},
set(v) {
value = v;
input.value = v;
}
});

// Handle input changes
input.oninput = (e) => set(node, e.target.value);

// Set the initial value
node.value = value;
return node;
}
Insert cell
Insert cell
viewof gpuOptionsInput = DataListInput(gpuOptions, {label: "Select GPU", value: gpuOptions[0]});

Insert cell
Insert cell
gpuOptionsInput
Insert cell
Insert cell
Inputs.bind(Inputs.radio(gpuOptions, {label: "GPU"}), viewof gpuOptionsInput)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more