Skip to content

Commit 13bb206

Browse files
add test, handle Vector{Any}
1 parent e100c0f commit 13bb206

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/app/dashapp.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function Base.getindex(component::DashBase.Component, id::AbstractString)
4848
component.id == id && return component
4949
hasproperty(component, :children) || return nothing
5050
cc = component.children
51-
cc isa Union{VecChildTypes, DashBase.Component} ? cc[id] : nothing
51+
cc isa Union{VecChildTypes, DashBase.Component, Vector{Any}} ? cc[id] : nothing
5252
end
5353
function Base.getindex(children::VecChildTypes, id::AbstractString)
5454
for element in children
@@ -57,6 +57,14 @@ function Base.getindex(children::VecChildTypes, id::AbstractString)
5757
el !== nothing && return el
5858
end
5959
end
60+
function Base.getindex(children::AbstractVector, id::AbstractString)
61+
for element in children
62+
hasproperty(element, :id) || continue
63+
element.id == id && return element
64+
el = element[id]
65+
el !== nothing && return el
66+
end
67+
end
6068

6169
#only name, index_string and layout are available to set
6270
function Base.setproperty!(app::DashApp, property::Symbol, value)

test/core.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,17 @@ end
200200
end
201201
@test_throws ErrorException make_handler(app)
202202
end
203+
204+
@testset "Index by id" begin
205+
app = dash()
206+
app.layout = html_div() do
207+
dcc_input(id = "my-id", value="initial value", type = "text"),
208+
html_div(id = "my-div", children = [
209+
html_div(),
210+
"string",
211+
html_div(id = "target")
212+
]),
213+
html_div(id = "my-div2")
214+
end
215+
@test app["target"].id == "target"
216+
end

0 commit comments

Comments
 (0)