Skip to content

Commit

Permalink
Ensure Chip and Radio work outside group
Browse files Browse the repository at this point in the history
  • Loading branch information
RenaudLN committed Oct 12, 2024
1 parent 71c312d commit d424f3d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ts/components/core/chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Chip = (props: Props) => {
setProps({ checked });
};

const { chipOnClick } = React.useContext(ChipGroupContext);
const { chipOnClick } = React.useContext(ChipGroupContext) || {};

if (controlled) {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/ts/components/core/radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Radio = (props: Props) => {
...others
} = props;

const { radioOnClick } = React.useContext(RadioGroupContext);
const { radioOnClick } = React.useContext(RadioGroupContext) || {};

return (
<MantineRadio
Expand Down
20 changes: 17 additions & 3 deletions tests/test_chip_group.py → tests/test_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def update_output(selected_values):
return app


def test_001cg_chip_group(dash_duo):
def test_001ch_chip_group(dash_duo):

app = chipgroup_app()
dash_duo.start_server(app)
Expand All @@ -51,7 +51,7 @@ def test_001cg_chip_group(dash_duo):
dash_duo.wait_for_text_to_equal("#output", "Selected: option2")


def test_002cg_chip_group_deselectable(dash_duo):
def test_002ch_chip_group_deselectable(dash_duo):

app = chipgroup_app(deselectable=True)
dash_duo.start_server(app)
Expand All @@ -66,7 +66,7 @@ def test_002cg_chip_group_deselectable(dash_duo):
dash_duo.wait_for_text_to_equal("#output", "Selected: None")


def test_003cg_chip_group_deselectable_multiple(dash_duo):
def test_003ch_chip_group_deselectable_multiple(dash_duo):

app = chipgroup_app(deselectable=True, multiple=True)
dash_duo.start_server(app)
Expand All @@ -84,3 +84,17 @@ def test_003cg_chip_group_deselectable_multiple(dash_duo):
dash_duo.wait_for_text_to_equal("#output", "Selected: ['option1']")
option1.click()
dash_duo.wait_for_text_to_equal("#output", "Selected: []")


def test_004ch_single_chip(dash_duo):

app = Dash(__name__)

app.layout = dmc.MantineProvider(dmc.Chip("Radio a", value="a", id="a"))

dash_duo.start_server(app)

# Wait for the app to load
dash_duo.wait_for_element("#a")

assert not dash_duo.get_logs()
18 changes: 16 additions & 2 deletions tests/test_radio_group.py → tests/test_radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def update_output(selected_values):
return app


def test_001rg_radio_group(dash_duo):
def test_001ra_radio_group(dash_duo):

app = radiogroup_app()
dash_duo.start_server(app)
Expand All @@ -51,7 +51,7 @@ def test_001rg_radio_group(dash_duo):
dash_duo.wait_for_text_to_equal("#output", "Selected: option2")


def test_002rg_radio_group_deselectable(dash_duo):
def test_002ra_radio_group_deselectable(dash_duo):

app = radiogroup_app(deselectable=True)
dash_duo.start_server(app)
Expand All @@ -64,3 +64,17 @@ def test_002rg_radio_group_deselectable(dash_duo):
dash_duo.wait_for_text_to_equal("#output", "Selected: option1")
option1.click()
dash_duo.wait_for_text_to_equal("#output", "Selected: None")


def test_003ra_single_radio(dash_duo):

app = Dash(__name__)

app.layout = dmc.MantineProvider(dmc.Radio(label="Radio a", value="a", id="a"))

dash_duo.start_server(app)

# Wait for the app to load
dash_duo.wait_for_element("#a")

assert not dash_duo.get_logs()

0 comments on commit d424f3d

Please sign in to comment.