Support mixed String/Pair entries in Dropdown

This commit is contained in:
TEC 2022-10-16 18:36:01 +08:00
parent a984faa95c
commit 585e04463f
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 12 additions and 0 deletions

View File

@ -464,6 +464,18 @@ Dropdown(opts::Union{Vector{String}, Vector{Pair{String, String}}}) =
Dropdown(Options(opts))
Dropdown(gopts::Vector{Pair{String, Vector}}) =
Dropdown([OptGroup(gopt) for gopt in gopts])
Dropdown(opts::Vector{Any}) =
if Pair{String,String} in typeof.(opts)
opts = map(opts) do o
if o isa String
o => o
else
o
end
end |> Vector{Pair{String,String}} |> Dropdown
else
throw(ArgumentError("Expecected opts to be a Vector{Union{String, Pair{String, String}}}."))
end
html_element(::Dropdown) = "select"
function html_content(d::Dropdown{Options}, value)