From f055b10661011300b6ea63cf948f7ff5cd773f7f Mon Sep 17 00:00:00 2001 From: Peter Fine Date: Mon, 9 Dec 2024 11:37:07 +0000 Subject: [PATCH 1/3] add disabled state to individual SegmentedControl items --- src/ts/components/core/SegmentedControl.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ts/components/core/SegmentedControl.tsx b/src/ts/components/core/SegmentedControl.tsx index ba5fca6b..eb21b804 100644 --- a/src/ts/components/core/SegmentedControl.tsx +++ b/src/ts/components/core/SegmentedControl.tsx @@ -66,6 +66,7 @@ const SegmentedControl = (props: Props) => { const rItem = { value: item["value"], label: renderDashComponent(item["label"]), + disabled: item["disabled"], }; renderedData.push(rItem); } From 28741668f4b3ab1f45374e0bbb814bf1c6489d82 Mon Sep 17 00:00:00 2001 From: Peter Fine Date: Mon, 9 Dec 2024 11:45:53 +0000 Subject: [PATCH 2/3] disabled segmentedcontrol options changelog update --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94def7d1..029c5482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +# Unreleased + +### Added +- Added `disabled` prop for individual options on a `SegmentedControl` #451 by @petefine + # 0.15.1 ### Added From 6cc0aaba6e8f98bef4c9aa59e2a5c55a7676a201 Mon Sep 17 00:00:00 2001 From: Peter Fine Date: Mon, 9 Dec 2024 14:11:28 +0000 Subject: [PATCH 3/3] segmented_control docstring and unit test Actual author here was AnnMarieW --- src/ts/components/core/SegmentedControl.tsx | 2 +- tests/test_segmented_control.py | 45 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/test_segmented_control.py diff --git a/src/ts/components/core/SegmentedControl.tsx b/src/ts/components/core/SegmentedControl.tsx index eb21b804..86c579d7 100644 --- a/src/ts/components/core/SegmentedControl.tsx +++ b/src/ts/components/core/SegmentedControl.tsx @@ -46,7 +46,7 @@ interface Props withItemsBorders?: boolean; } -/** SegmentedControl */ +/** SegmentedControl is a horizontal selector for choosing one option from multiple segments */ const SegmentedControl = (props: Props) => { const { data, diff --git a/tests/test_segmented_control.py b/tests/test_segmented_control.py new file mode 100644 index 00000000..72b019bb --- /dev/null +++ b/tests/test_segmented_control.py @@ -0,0 +1,45 @@ +from dash import Dash, html, Output, Input, _dash_renderer +import dash_mantine_components as dmc + +_dash_renderer._set_react_version("18.2.0") + + +def test_001se_segmented_control(dash_duo): + app = Dash() + app.layout = dmc.MantineProvider( + [ + dmc.SegmentedControl( + id="segmented", + data=[ + {"label": "a", "value": "a"}, + {"label": "b", "value": "b", "disabled": True}, + {"label": "c", "value": "c"}, + ], + value="a", + ), + html.Div(id="output"), + ] + ) + + @app.callback( + Output("output", "children"), + Input("segmented", "value"), + ) + def update(choice): + return f"{choice=}" + + dash_duo.start_server(app) + + # Wait for the app to load + dash_duo.wait_for_text_to_equal("#output", "choice='a'") + + option_b = dash_duo.find_element("input[value='b']") + + # Verify that "b" is disabled + assert option_b.get_attribute("disabled") == "true" + + option_c = dash_duo.find_element("input[value='c']").find_element_by_xpath("./..") + option_c.click() + dash_duo.wait_for_text_to_equal("#output", "choice='c'") + + assert dash_duo.get_logs() == []