diff --git a/src/Builtins.jl b/src/Builtins.jl index 121e86a4..1280e8e7 100644 --- a/src/Builtins.jl +++ b/src/Builtins.jl @@ -146,9 +146,10 @@ end get(textfield::TextField) = textfield.default - """A dropdown menu (``) - the user can choose one or more of the `options`, an array of `Strings. + +See [`Select`](@ref) for a version that allows only one selected item. + +`options` can also be an array of pairs `key::String => value::Any`. The `key` is returned via `@bind`; the `value` is shown. + +See the [Mozilla docs about `select`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select) + +# Examples +`@bind veg MultiSelect(["potato", "carrot"])` + +`@bind veg MultiSelect(["potato" => "🥔", "carrot" => "🥕"])` + +`@bind veg MultiSelect(["potato" => "🥔", "carrot" => "🥕"], default=["carrot"])`""" +struct MultiSelect + options::Array{Pair{<:AbstractString,<:Any},1} + default::Union{Missing, AbstractVector{AbstractString}} +end +MultiSelect(options::Array{<:AbstractString,1}; default=missing) = MultiSelect([o => o for o in options], default) +MultiSelect(options::Array{<:Pair{<:AbstractString,<:Any},1}; default=missing) = MultiSelect(options, default) + +function show(io::IO, ::MIME"text/html", select::MultiSelect) + withtag(io, Symbol("select multiple")) do + for o in select.options + print(io, """") + end + end +end + +get(select::MultiSelect) = ismissing(select.default) ? Any[] : select.default + """A file upload box. The chosen file will be read by the browser, and the bytes are sent back to Julia. The optional `accept` argument can be an array of `MIME`s. The user can only select files with these MIME. If only `image/*` MIMEs are allowed, then smartphone browsers will open the camera instead of a file browser.