diff --git a/frontend/taipy-gui/src/components/Taipy/Toggle.spec.tsx b/frontend/taipy-gui/src/components/Taipy/Toggle.spec.tsx index f48a15cb06..c4de55b427 100644 --- a/frontend/taipy-gui/src/components/Taipy/Toggle.spec.tsx +++ b/frontend/taipy-gui/src/components/Taipy/Toggle.spec.tsx @@ -124,34 +124,34 @@ describe("Toggle Component", () => { type: "SEND_UPDATE_ACTION", }); }); - it("dispatch unselected_value on deselection when allowUnselect", async () => { + it("dispatch nothing on deselection by default", async () => { const dispatch = jest.fn(); const state: TaipyState = INITIAL_STATE; const { getByText } = render( - + ); const elt = getByText("Item 2"); await userEvent.click(elt); - expect(dispatch).toHaveBeenCalledWith({ - name: "varname", - payload: { value: "uv" }, - propagate: true, - type: "SEND_UPDATE_ACTION", - }); + expect(dispatch).not.toHaveBeenCalled(); }); - it("dispatch nothing on deselection by default", async () => { + it("dispatch null on deselection when allowUnselect", async () => { const dispatch = jest.fn(); const state: TaipyState = INITIAL_STATE; const { getByText } = render( - + ); const elt = getByText("Item 2"); await userEvent.click(elt); - expect(dispatch).not.toHaveBeenCalled(); + expect(dispatch).toHaveBeenCalledWith({ + name: "varname", + payload: { value: null }, + propagate: true, + type: "SEND_UPDATE_ACTION", + }); }); describe("As Switch", () => { diff --git a/frontend/taipy-gui/src/components/Taipy/Toggle.tsx b/frontend/taipy-gui/src/components/Taipy/Toggle.tsx index 36b0002f4b..9933f80227 100644 --- a/frontend/taipy-gui/src/components/Taipy/Toggle.tsx +++ b/frontend/taipy-gui/src/components/Taipy/Toggle.tsx @@ -14,26 +14,25 @@ import React, { MouseEvent, SyntheticEvent, useCallback, useEffect, useMemo, useState } from "react"; import Box from "@mui/material/Box"; import Switch from "@mui/material/Switch"; -import Typography from "@mui/material/Typography"; import ToggleButton from "@mui/material/ToggleButton"; import ToggleButtonGroup from "@mui/material/ToggleButtonGroup"; import Tooltip from "@mui/material/Tooltip"; +import Typography from "@mui/material/Typography"; +import { FormControlLabel, SxProps } from "@mui/material"; import { createSendUpdateAction } from "../../context/taipyReducers"; -import ThemeToggle, { emptyStyle } from "./ThemeToggle"; -import { LovProps, useLovListMemo } from "./lovUtils"; import { useClassNames, useDispatch, useDynamicProperty, useModule } from "../../utils/hooks"; -import { getCssSize, getSuffixedClassNames, getUpdateVar } from "./utils"; import { Icon, IconAvatar } from "../../utils/icon"; -import { FormControlLabel, SxProps } from "@mui/material"; import { getComponentClassName } from "./TaipyStyle"; +import ThemeToggle, { emptyStyle } from "./ThemeToggle"; +import { LovProps, useLovListMemo } from "./lovUtils"; +import { getCssSize, getSuffixedClassNames, getUpdateVar } from "./utils"; const baseGroupSx = { verticalAlign: "middle" }; interface ToggleProps extends LovProps { style?: SxProps; label?: string; - unselectedValue?: string; allowUnselect?: boolean; mode?: string; isSwitch?: boolean; @@ -49,14 +48,13 @@ const Toggle = (props: ToggleProps) => { propagate = true, lov, defaultLov = "", - unselectedValue = "", updateVars = "", valueById, mode = "", isSwitch = false, } = props; const dispatch = useDispatch(); - const [value, setValue] = useState(props.defaultValue); + const [value, setValue] = useState(props.defaultValue); const [bVal, setBVal] = useState(() => typeof props.defaultValue === "boolean" ? props.defaultValue @@ -85,7 +83,7 @@ const Toggle = (props: ToggleProps) => { dispatch( createSendUpdateAction( updateVarName, - val === null ? unselectedValue : val, + val, module, props.onChange, propagate, @@ -93,17 +91,7 @@ const Toggle = (props: ToggleProps) => { ) ); }, - [ - unselectedValue, - updateVarName, - propagate, - dispatch, - updateVars, - valueById, - props.onChange, - props.allowUnselect, - module, - ] + [updateVarName, propagate, dispatch, updateVars, valueById, props.onChange, props.allowUnselect, module] ); const changeSwitchValue = useCallback( diff --git a/taipy/gui/_renderers/factory.py b/taipy/gui/_renderers/factory.py index 5c14efd476..8081d8248b 100644 --- a/taipy/gui/_renderers/factory.py +++ b/taipy/gui/_renderers/factory.py @@ -626,7 +626,6 @@ class _Factory: ("hover_text", PropertyType.dynamic_string), ("label",), ("value_by_id", PropertyType.boolean), - ("unselected_value", PropertyType.string, ""), ("allow_unselect", PropertyType.boolean), ("on_change", PropertyType.function), ("mode",), diff --git a/taipy/gui/gui.py b/taipy/gui/gui.py index 89ee496b43..0a92334d9a 100644 --- a/taipy/gui/gui.py +++ b/taipy/gui/gui.py @@ -735,7 +735,7 @@ def __front_end_update( elif rel_var and isinstance(current_value, _TaipyLovValue): # pragma: no cover lov_holder = _getscopeattr_drill(self, self.__evaluator.get_hash_from_expr(rel_var)) if isinstance(lov_holder, _TaipyLov): - if value: + if isinstance(value, str): val = value if isinstance(value, list) else [value] elt_4_ids = self.__adapter._get_elt_per_ids(lov_holder.get_name(), lov_holder.get()) ret_val = [elt_4_ids.get(x, x) for x in val] diff --git a/taipy/gui/viselements.json b/taipy/gui/viselements.json index a6cc9fa1b4..7349feb0a2 100644 --- a/taipy/gui/viselements.json +++ b/taipy/gui/viselements.json @@ -275,12 +275,6 @@ "default_value": "False", "doc": "If set, this allows de-selection and the value is set to unselected_value." }, - { - "name": "unselected_value", - "type": "Any", - "default_value": "None", - "doc": "Value assigned to value when no item is selected." - }, { "name": "mode", "type": "str", @@ -1632,7 +1626,7 @@ } ], [ - "alert", + "alert", { "inherits": ["shared"], "properties": [ @@ -1662,7 +1656,7 @@ "doc": "If False, the alert is hidden." } ] - } + } ], [ "status", @@ -1842,7 +1836,7 @@ } ] } - ] + ] ], "blocks": [ [ diff --git a/tests/gui/builder/control/test_toggle.py b/tests/gui/builder/control/test_toggle.py index 419b46542b..1842ed2c8e 100644 --- a/tests/gui/builder/control/test_toggle.py +++ b/tests/gui/builder/control/test_toggle.py @@ -16,14 +16,14 @@ def test_toggle_builder(gui: Gui, helpers): with tgb.Page(frame=None) as page: tgb.toggle(theme=True) # type: ignore[attr-defined] - expected_list = ["