Skip to content

Commit

Permalink
Merge pull request #451 from petefine/disabled_segmented_control_item
Browse files Browse the repository at this point in the history
disabled SegmentedControl options
  • Loading branch information
AnnMarieW authored Dec 11, 2024
2 parents 758065c + 6cc0aab commit 229d34d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

# Unreleased

### Added
- Added `disabled` prop for individual options on a `SegmentedControl` #451 by @petefine

# 0.15.1

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/ts/components/core/SegmentedControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -66,6 +66,7 @@ const SegmentedControl = (props: Props) => {
const rItem = {
value: item["value"],
label: renderDashComponent(item["label"]),
disabled: item["disabled"],
};
renderedData.push(rItem);
}
Expand Down
45 changes: 45 additions & 0 deletions tests/test_segmented_control.py
Original file line number Diff line number Diff line change
@@ -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() == []

0 comments on commit 229d34d

Please sign in to comment.