From ea0ed8f170999de20e6fe8936369d87d05a82345 Mon Sep 17 00:00:00 2001 From: elvis kahoro Date: Fri, 2 Oct 2026 13:34:42 -0700 Subject: [PATCH] Preserve custom styling on context menu shortcuts --- components/ui/context_menu.py | 2 +- tests/test_context_menu.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/test_context_menu.py diff --git a/components/ui/context_menu.py b/components/ui/context_menu.py index 51444d64..b38f8dda 100644 --- a/components/ui/context_menu.py +++ b/components/ui/context_menu.py @@ -344,7 +344,7 @@ class ContextMenuShortcut(Span, CoreComponent): @classmethod def create(cls, *children, **props) -> Span: props["data-slot"] = "context-menu-shortcut" - props["class_name"] = ClassNames.SHORTCUT + cls.set_class_name(ClassNames.SHORTCUT, props) return super().create(*children, **props) diff --git a/tests/test_context_menu.py b/tests/test_context_menu.py new file mode 100644 index 00000000..f41d9ba9 --- /dev/null +++ b/tests/test_context_menu.py @@ -0,0 +1,34 @@ +import sys +from pathlib import Path + +ROOT_DIR = Path(__file__).parent.parent +sys.path.insert(0, str(ROOT_DIR)) + +from components.ui.context_menu import ClassNames, ContextMenuShortcut # noqa: E402 + + +def test_context_menu_shortcut_uses_default_classes() -> None: + shortcut = ContextMenuShortcut.create("Ctrl+C") + + assert ClassNames.SHORTCUT in str(shortcut.class_name) + + +def test_context_menu_shortcut_merges_custom_class_name() -> None: + shortcut = ContextMenuShortcut.create("Ctrl+C", class_name="custom-shortcut") + + assert ClassNames.SHORTCUT in str(shortcut.class_name) + assert "custom-shortcut" in str(shortcut.class_name) + + +def test_context_menu_shortcut_unstyled_omits_default_classes() -> None: + shortcut = ContextMenuShortcut.create("Ctrl+C", unstyled=True) + + assert str(shortcut.class_name) == "" + + +def test_context_menu_shortcut_unstyled_keeps_custom_class_name() -> None: + shortcut = ContextMenuShortcut.create( + "Ctrl+C", class_name="custom-shortcut", unstyled=True + ) + + assert str(shortcut.class_name) == "custom-shortcut"