Skip to content

Commit 6945807

Browse files
committed
Fix multi set_props calls
1 parent ba5e2ab commit 6945807

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

dash/_callback_context.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ def timing_information(self):
252252
def set_props(self, component_id: typing.Union[str, dict], props: dict):
253253
ctx_value = _get_context_value()
254254
_id = stringify_id(component_id)
255-
ctx_value.updated_props[_id] = props
255+
updates = ctx_value.updated_props.get(_id)
256+
if updates is not None:
257+
ctx_value.updated_props[_id] = {**updates, **props}
258+
else:
259+
ctx_value.updated_props[_id] = props
256260

257261

258262
callback_context = CallbackContext()

tests/integration/callbacks/test_arbitrary_callbacks.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,26 @@ def on_click(clicked):
165165
".dash-fe-error__title",
166166
"Callback error with no output from input start.n_clicks",
167167
)
168+
169+
170+
def test_arb006_multi_set_props(dash_duo):
171+
app = Dash()
172+
173+
app.layout = [
174+
html.Button("start", id="start"),
175+
html.Div("initial", id="output"),
176+
]
177+
178+
@app.callback(
179+
Input("start", "n_clicks"),
180+
)
181+
def on_click(_):
182+
set_props("output", {"children": "changed"})
183+
set_props("output", {"style": {"background": "rgb(255,0,0)"}})
184+
185+
dash_duo.start_server(app)
186+
dash_duo.wait_for_element("#start").click()
187+
dash_duo.wait_for_text_to_equal("#output", "changed")
188+
dash_duo.wait_for_style_to_equal(
189+
"#output", "background-color", "rgba(255, 0, 0, 1)"
190+
)

0 commit comments

Comments
 (0)