From d366fa6440c30f8da40a42869407e43ca42efbfb Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 20 Nov 2026 02:48:00 -0800 Subject: [PATCH 01/12] Add typed menu-item styling properties --- docs/api-migrations.md | 30 ++++++ src/lui_elements.ml | 32 +++++- src/lui_elements.mli | 90 ++++++++++++++++ src/lui_json_view.ml | 6 +- src/lui_wire_schema.ml | 2 +- tooling/test/menu-item-style.test.mjs | 143 ++++++++++++++++++++++++++ 6 files changed, 298 insertions(+), 5 deletions(-) create mode 100644 tooling/test/menu-item-style.test.mjs diff --git a/docs/api-migrations.md b/docs/api-migrations.md index 99d09a3b..5626aa3e 100644 --- a/docs/api-migrations.md +++ b/docs/api-migrations.md @@ -1,5 +1,35 @@ # LUI API migration guide +### Typed menu-item typography and interaction styling + +`menu_item`, `dropdown_menu_item` and `toolbar_menu_item` now accept the same +optional typography and interaction styling properties. Each has a matching +`_signal` argument: `font_size`, `font_weight`, `font_family`, `font_style`, +`line_height`, `letter_spacing`, `text_decoration`, `white_space`, +`text_overflow`, `overflow`, `hover_background`, `hover_foreground`, +`focus_within_background`, `focus_within_border` and `focus_shadow`. +The enum-valued properties use the existing closed text vocabularies. + +Move ordinary-view post-mount styling onto the slot constructor rather than +erasing or casting its restricted capability: + +```ocaml +dropdown_menu + [ dropdown_menu_item ~text:"Open" ~font_size:"0.875rem" + ~line_height:"1.42857" ~hover_background:"muted" + ~hover_foreground:(reactive (fun active -> + if active then "primary" else "foreground") selected) + ~focus_shadow:"inset 0 0 0 2px blue" [] ] +``` + +The existing slot adapters retain these properties. Signals are borrowed; +their current values override static values, and subsequent publications +update the same node. Omitted properties remain unset, preserving all existing +defaults. The JSON menu-item renderer accepts the same static properties. +The language-neutral menu-item view contract includes these properties too. +This exposes existing wire properties only; the wire vocabulary, admission +tables, backend defaults and event behavior are unchanged. + ### Apple row intrinsic text priority Non-growing `text`, `heading`, and `paragraph` children in Apple rows now diff --git a/src/lui_elements.ml b/src/lui_elements.ml index f022c693..cc0b1d8b 100644 --- a/src/lui_elements.ml +++ b/src/lui_elements.ml @@ -2307,10 +2307,40 @@ let accordion ?key ?height ?accessibility_identifier ?accessibility_identifier_s mount_children context node children; node -let menu_item ?key ?gap ?main ?cross ?grow ?padding ?padding_horizontal ?padding_vertical ?margin ?margin_horizontal ?margin_vertical ?margin_top ?margin_right ?margin_bottom ?margin_left ?background ?foreground ?border_color ?border_width ?corner_radius ?width ?height ?min_width ?max_width ?min_height ?max_height ?container_relative_frame ?container_relative_frame_inset ?accessibility_identifier ?accessibility_identifier_signal ?foreground_signal ?background_signal ?style_class ?data_attrs ?data_attrs_signal ?on_appear ?on_pointer_enter ?on_pointer_leave ?text ?text_signal ?icon ?icon_signal ?selection_placement ?variant ?size ?selected ?checked ?selected_signal ?checked_signal ?disabled ?disabled_signal ?on_press ?on_press_detail ?on_pointer_down ?on_pointer_up ?on_context_menu ?tooltip ?tooltip_signal ?shortcut_hint ?shortcut_hint_signal ?transition (children : t list) : t = +let menu_item ?key ?gap ?main ?cross ?grow ?padding ?padding_horizontal ?padding_vertical ?margin ?margin_horizontal ?margin_vertical ?margin_top ?margin_right ?margin_bottom ?margin_left ?background ?foreground ?border_color ?border_width ?corner_radius ?width ?height ?min_width ?max_width ?min_height ?max_height ?container_relative_frame ?container_relative_frame_inset ?accessibility_identifier ?accessibility_identifier_signal ?foreground_signal ?background_signal ?style_class ?data_attrs ?data_attrs_signal ?on_appear ?on_pointer_enter ?on_pointer_leave ?text ?text_signal ?icon ?icon_signal ?selection_placement ?variant ?size ?selected ?checked ?selected_signal ?checked_signal ?disabled ?disabled_signal ?on_press ?on_press_detail ?on_pointer_down ?on_pointer_up ?on_context_menu ?tooltip ?tooltip_signal ?shortcut_hint ?shortcut_hint_signal ?font_size ?font_size_signal ?font_weight ?font_weight_signal ?font_family ?font_family_signal ?font_style ?font_style_signal ?line_height ?line_height_signal ?letter_spacing ?letter_spacing_signal ?text_decoration ?text_decoration_signal ?white_space ?white_space_signal ?text_overflow ?text_overflow_signal ?overflow ?overflow_signal ?hover_background ?hover_background_signal ?hover_foreground ?hover_foreground_signal ?focus_within_background ?focus_within_background_signal ?focus_within_border ?focus_within_border_signal ?focus_shadow ?focus_shadow_signal ?transition (children : t list) : t = fun context parent -> let node = Lui_ui.menu_item context in apply_universal ?key ?gap ?main ?cross ?grow ?padding ?padding_horizontal ?padding_vertical ?margin ?margin_horizontal ?margin_vertical ?margin_top ?margin_right ?margin_bottom ?margin_left ?background ?foreground ?border_color ?border_width ?corner_radius ?width ?height ?min_width ?max_width ?min_height ?max_height ?container_relative_frame ?container_relative_frame_inset ?accessibility_identifier ?accessibility_identifier_signal ?foreground_signal ?background_signal ?style_class ?data_attrs ?data_attrs_signal ?on_appear ?on_pointer_enter ?on_pointer_leave ?transition context node; + Option.iter (Lui_ui.font_size context node) font_size; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node FontSize signal_) font_size_signal; + Option.iter (Lui_ui.font_weight context node) font_weight; + Option.iter (fun signal_ -> Lui_ui.int_property_signal context node FontWeight signal_) font_weight_signal; + Option.iter (Lui_ui.font_family context node) font_family; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node FontFamily signal_) font_family_signal; + Option.iter (Lui_ui.font_style context node) (Option.map font_style_value font_style); + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node FontStyle (owned_map context font_style_value signal_)) font_style_signal; + Option.iter (Lui_ui.line_height context node) line_height; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node LineHeight signal_) line_height_signal; + Option.iter (Lui_ui.letter_spacing context node) letter_spacing; + Option.iter (fun signal_ -> Lui_ui.float_property_signal context node LetterSpacing signal_) letter_spacing_signal; + Option.iter (Lui_ui.text_decoration context node) text_decoration; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node TextDecoration signal_) text_decoration_signal; + Option.iter (Lui_ui.white_space context node) (Option.map white_space_value white_space); + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node WhiteSpace (owned_map context white_space_value signal_)) white_space_signal; + Option.iter (Lui_ui.text_overflow context node) (Option.map text_overflow_value text_overflow); + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node TextOverflow (owned_map context text_overflow_value signal_)) text_overflow_signal; + Option.iter (Lui_ui.overflow context node) (Option.map overflow_value overflow); + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node Overflow (owned_map context overflow_value signal_)) overflow_signal; + Option.iter (Lui_ui.hover_background context node) hover_background; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node HoverBackground signal_) hover_background_signal; + Option.iter (Lui_ui.hover_foreground context node) hover_foreground; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node HoverForeground signal_) hover_foreground_signal; + Option.iter (Lui_ui.focus_within_background context node) focus_within_background; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node FocusWithinBackground signal_) focus_within_background_signal; + Option.iter (Lui_ui.focus_within_border context node) focus_within_border; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node FocusWithinBorder signal_) focus_within_border_signal; + Option.iter (Lui_ui.focus_shadow context node) focus_shadow; + Option.iter (fun signal_ -> Lui_ui.string_property_signal context node FocusShadow signal_) focus_shadow_signal; Option.iter (Lui_ui.string_property context node TextValue) text; Option.iter (Lui_ui.string_property_signal context node TextValue) text_signal; Option.iter (Lui_ui.string_property context node InlineIconName) (Option.map icon_value icon); diff --git a/src/lui_elements.mli b/src/lui_elements.mli index aaec9331..2822ed6c 100644 --- a/src/lui_elements.mli +++ b/src/lui_elements.mli @@ -3438,6 +3438,36 @@ val menu_item : ?tooltip_signal:string Signal.signal -> ?shortcut_hint:string -> ?shortcut_hint_signal:string Signal.signal -> + ?font_size:string -> + ?font_size_signal:string Signal.signal -> + ?font_weight:int -> + ?font_weight_signal:int Signal.signal -> + ?font_family:string -> + ?font_family_signal:string Signal.signal -> + ?font_style:font_style -> + ?font_style_signal:font_style Signal.signal -> + ?line_height:string -> + ?line_height_signal:string Signal.signal -> + ?letter_spacing:float -> + ?letter_spacing_signal:float Signal.signal -> + ?text_decoration:string -> + ?text_decoration_signal:string Signal.signal -> + ?white_space:white_space -> + ?white_space_signal:white_space Signal.signal -> + ?text_overflow:text_overflow -> + ?text_overflow_signal:text_overflow Signal.signal -> + ?overflow:overflow -> + ?overflow_signal:overflow Signal.signal -> + ?hover_background:string -> + ?hover_background_signal:string Signal.signal -> + ?hover_foreground:string -> + ?hover_foreground_signal:string Signal.signal -> + ?focus_within_background:string -> + ?focus_within_background_signal:string Signal.signal -> + ?focus_within_border:string -> + ?focus_within_border_signal:string Signal.signal -> + ?focus_shadow:string -> + ?focus_shadow_signal:string Signal.signal -> ?transition:string -> t list -> t val list_item : ?key:string -> @@ -4635,6 +4665,36 @@ val toolbar_menu_item : ?tooltip_signal:string Signal.signal -> ?shortcut_hint:string -> ?shortcut_hint_signal:string Signal.signal -> + ?font_size:string -> + ?font_size_signal:string Signal.signal -> + ?font_weight:int -> + ?font_weight_signal:int Signal.signal -> + ?font_family:string -> + ?font_family_signal:string Signal.signal -> + ?font_style:font_style -> + ?font_style_signal:font_style Signal.signal -> + ?line_height:string -> + ?line_height_signal:string Signal.signal -> + ?letter_spacing:float -> + ?letter_spacing_signal:float Signal.signal -> + ?text_decoration:string -> + ?text_decoration_signal:string Signal.signal -> + ?white_space:white_space -> + ?white_space_signal:white_space Signal.signal -> + ?text_overflow:text_overflow -> + ?text_overflow_signal:text_overflow Signal.signal -> + ?overflow:overflow -> + ?overflow_signal:overflow Signal.signal -> + ?hover_background:string -> + ?hover_background_signal:string Signal.signal -> + ?hover_foreground:string -> + ?hover_foreground_signal:string Signal.signal -> + ?focus_within_background:string -> + ?focus_within_background_signal:string Signal.signal -> + ?focus_within_border:string -> + ?focus_within_border_signal:string Signal.signal -> + ?focus_shadow:string -> + ?focus_shadow_signal:string Signal.signal -> ?transition:string -> t list -> toolbar_el val toolbar_menu_trigger : ?key:string -> @@ -4896,6 +4956,36 @@ val dropdown_menu_item : ?tooltip_signal:string Signal.signal -> ?shortcut_hint:string -> ?shortcut_hint_signal:string Signal.signal -> + ?font_size:string -> + ?font_size_signal:string Signal.signal -> + ?font_weight:int -> + ?font_weight_signal:int Signal.signal -> + ?font_family:string -> + ?font_family_signal:string Signal.signal -> + ?font_style:font_style -> + ?font_style_signal:font_style Signal.signal -> + ?line_height:string -> + ?line_height_signal:string Signal.signal -> + ?letter_spacing:float -> + ?letter_spacing_signal:float Signal.signal -> + ?text_decoration:string -> + ?text_decoration_signal:string Signal.signal -> + ?white_space:white_space -> + ?white_space_signal:white_space Signal.signal -> + ?text_overflow:text_overflow -> + ?text_overflow_signal:text_overflow Signal.signal -> + ?overflow:overflow -> + ?overflow_signal:overflow Signal.signal -> + ?hover_background:string -> + ?hover_background_signal:string Signal.signal -> + ?hover_foreground:string -> + ?hover_foreground_signal:string Signal.signal -> + ?focus_within_background:string -> + ?focus_within_background_signal:string Signal.signal -> + ?focus_within_border:string -> + ?focus_within_border_signal:string Signal.signal -> + ?focus_shadow:string -> + ?focus_shadow_signal:string Signal.signal -> ?transition:string -> t list -> dropdown_menu_item_el val dropdown_menu_trigger : ?key:string -> diff --git a/src/lui_json_view.ml b/src/lui_json_view.ml index cd1e8309..7adf72ad 100644 --- a/src/lui_json_view.ml +++ b/src/lui_json_view.ml @@ -651,7 +651,7 @@ let rec element ~emit (node : value) : E.t = ?key:s.s_key ?height:s.s_height ?accessibility_identifier:(v_str props "accessibility-identifier") ?style_class:s.s_class ?on_appear:(ev "appear" emit props) ~title:(required "accordion.title" (v_str props "text")) ?selected:(v_bool props "selected") ?accordion_height:(v_int props "accordion-height") ?on_toggle:(ev_toggle "toggle" emit props) (List.map (element ~emit) child_nodes) | "menu-item" -> E.menu_item - ?key:s.s_key ?gap:s.s_gap ?main:s.s_main ?cross:s.s_cross ?grow:s.s_grow ?padding:s.s_pad ?padding_horizontal:s.s_pad_h ?padding_vertical:s.s_pad_v ?margin:s.s_margin ?margin_horizontal:s.s_margin_h ?margin_vertical:s.s_margin_v ?margin_top:s.s_margin_top ?margin_right:s.s_margin_right ?margin_bottom:s.s_margin_bottom ?margin_left:s.s_margin_left ?background:s.s_bg ?foreground:s.s_fg ?border_color:s.s_border_color ?border_width:s.s_border_width ?corner_radius:s.s_radius ?width:s.s_width ?height:s.s_height ?min_width:s.s_min_width ?max_width:s.s_max_width ?min_height:s.s_min_height ?max_height:s.s_max_height ?container_relative_frame:(frame_axes_opt (v_str props "container-relative-frame")) ?container_relative_frame_inset:(v_int props "container-relative-frame-inset") ?accessibility_identifier:(v_str props "accessibility-identifier") ?style_class:s.s_class ?on_appear:(ev "appear" emit props) ?text:(v_str props "text") ?icon:(icon_prop props "icon") ?selection_placement:(icon_placement_opt (v_str props "selection-placement")) ?variant:(variant_opt (v_str props "variant")) ?size:(control_size_opt (v_str props "size")) ?selected:(v_bool props "selected") ?checked:(v_bool props "checked") ?disabled:(v_bool props "disabled") ?on_press:(ev "press" emit props) ?tooltip:(v_str props "tooltip") ?shortcut_hint:(v_str props "shortcut-hint") ?transition:(v_str props "transition") (List.map (element ~emit) child_nodes) + ?key:s.s_key ?gap:s.s_gap ?main:s.s_main ?cross:s.s_cross ?grow:s.s_grow ?padding:s.s_pad ?padding_horizontal:s.s_pad_h ?padding_vertical:s.s_pad_v ?margin:s.s_margin ?margin_horizontal:s.s_margin_h ?margin_vertical:s.s_margin_v ?margin_top:s.s_margin_top ?margin_right:s.s_margin_right ?margin_bottom:s.s_margin_bottom ?margin_left:s.s_margin_left ?background:s.s_bg ?foreground:s.s_fg ?border_color:s.s_border_color ?border_width:s.s_border_width ?corner_radius:s.s_radius ?width:s.s_width ?height:s.s_height ?min_width:s.s_min_width ?max_width:s.s_max_width ?min_height:s.s_min_height ?max_height:s.s_max_height ?container_relative_frame:(frame_axes_opt (v_str props "container-relative-frame")) ?container_relative_frame_inset:(v_int props "container-relative-frame-inset") ?accessibility_identifier:(v_str props "accessibility-identifier") ?style_class:s.s_class ?on_appear:(ev "appear" emit props) ?text:(v_str props "text") ?icon:(icon_prop props "icon") ?selection_placement:(icon_placement_opt (v_str props "selection-placement")) ?variant:(variant_opt (v_str props "variant")) ?size:(control_size_opt (v_str props "size")) ?selected:(v_bool props "selected") ?checked:(v_bool props "checked") ?disabled:(v_bool props "disabled") ?on_press:(ev "press" emit props) ?tooltip:(v_str props "tooltip") ?shortcut_hint:(v_str props "shortcut-hint") ?font_size:(v_str props "font-size") ?font_weight:(v_int props "font-weight") ?font_family:(v_str props "font-family") ?font_style:(font_style_opt (v_str props "font-style")) ?line_height:(v_str props "line-height") ?letter_spacing:(v_float props "letter-spacing") ?text_decoration:(v_str props "text-decoration") ?white_space:(white_space_opt (v_str props "white-space")) ?text_overflow:(text_overflow_opt (v_str props "text-overflow")) ?overflow:(overflow_opt (v_str props "overflow")) ?hover_background:(v_str props "hover-background") ?hover_foreground:(v_str props "hover-foreground") ?focus_within_background:(v_str props "focus-within-background") ?focus_within_border:(v_str props "focus-within-border") ?focus_shadow:(v_str props "focus-shadow") ?transition:(v_str props "transition") (List.map (element ~emit) child_nodes) | "list-item" -> E.list_item ?key:s.s_key ?main:s.s_main ?cross:s.s_cross ?grow:s.s_grow ?padding:s.s_pad ?padding_horizontal:s.s_pad_h ?padding_vertical:s.s_pad_v ?margin:s.s_margin ?margin_horizontal:s.s_margin_h ?margin_vertical:s.s_margin_v ?margin_top:s.s_margin_top ?margin_right:s.s_margin_right ?margin_bottom:s.s_margin_bottom ?margin_left:s.s_margin_left ?background:s.s_bg ?foreground:s.s_fg ?border_color:s.s_border_color ?border_width:s.s_border_width ?corner_radius:s.s_radius ?width:s.s_width ?height:s.s_height ?min_width:s.s_min_width ?max_width:s.s_max_width ?min_height:s.s_min_height ?max_height:s.s_max_height ?container_relative_frame:(frame_axes_opt (v_str props "container-relative-frame")) ?container_relative_frame_inset:(v_int props "container-relative-frame-inset") ?accessibility_identifier:(v_str props "accessibility-identifier") ?style_class:s.s_class ?on_appear:(ev "appear" emit props) ?text:(v_str props "text") ?icon:(icon_prop props "icon") ?icon_placement:(icon_placement_opt (v_str props "icon-placement")) ?role:(role_opt (v_str props "role")) ?tree_level:(v_int props "tree-level") ?expanded:(v_bool props "expanded") ?selected:(v_bool props "selected") ?disabled:(v_bool props "disabled") ?on_press:(ev "press" emit props) ?on_long_press:(ev "long-press" emit props) ?on_double_press:(ev "double-press" emit props) ?on_submit:(ev "submit" emit props) ?on_toggle:(ev_toggle "toggle" emit props) ?transition:(v_str props "transition") (List.map (element ~emit) child_nodes) @@ -964,7 +964,7 @@ E.toolbar_search_field and build_toolbar_menu_item ~emit props child_nodes : E.toolbar_el = let s = sty_of props in E.toolbar_menu_item - ?key:s.s_key ?gap:s.s_gap ?main:s.s_main ?cross:s.s_cross ?grow:s.s_grow ?padding:s.s_pad ?padding_horizontal:s.s_pad_h ?padding_vertical:s.s_pad_v ?margin:s.s_margin ?margin_horizontal:s.s_margin_h ?margin_vertical:s.s_margin_v ?margin_top:s.s_margin_top ?margin_right:s.s_margin_right ?margin_bottom:s.s_margin_bottom ?margin_left:s.s_margin_left ?background:s.s_bg ?foreground:s.s_fg ?border_color:s.s_border_color ?border_width:s.s_border_width ?corner_radius:s.s_radius ?width:s.s_width ?height:s.s_height ?min_width:s.s_min_width ?max_width:s.s_max_width ?min_height:s.s_min_height ?max_height:s.s_max_height ?container_relative_frame:(frame_axes_opt (v_str props "container-relative-frame")) ?container_relative_frame_inset:(v_int props "container-relative-frame-inset") ?accessibility_identifier:(v_str props "accessibility-identifier") ?style_class:s.s_class ?on_appear:(ev "appear" emit props) ?text:(v_str props "text") ?icon:(icon_prop props "icon") ?selection_placement:(icon_placement_opt (v_str props "selection-placement")) ?variant:(variant_opt (v_str props "variant")) ?size:(control_size_opt (v_str props "size")) ?selected:(v_bool props "selected") ?checked:(v_bool props "checked") ?disabled:(v_bool props "disabled") ?on_press:(ev "press" emit props) ?tooltip:(v_str props "tooltip") ?shortcut_hint:(v_str props "shortcut-hint") ?transition:(v_str props "transition") (List.map (element ~emit) child_nodes) + ?key:s.s_key ?gap:s.s_gap ?main:s.s_main ?cross:s.s_cross ?grow:s.s_grow ?padding:s.s_pad ?padding_horizontal:s.s_pad_h ?padding_vertical:s.s_pad_v ?margin:s.s_margin ?margin_horizontal:s.s_margin_h ?margin_vertical:s.s_margin_v ?margin_top:s.s_margin_top ?margin_right:s.s_margin_right ?margin_bottom:s.s_margin_bottom ?margin_left:s.s_margin_left ?background:s.s_bg ?foreground:s.s_fg ?border_color:s.s_border_color ?border_width:s.s_border_width ?corner_radius:s.s_radius ?width:s.s_width ?height:s.s_height ?min_width:s.s_min_width ?max_width:s.s_max_width ?min_height:s.s_min_height ?max_height:s.s_max_height ?container_relative_frame:(frame_axes_opt (v_str props "container-relative-frame")) ?container_relative_frame_inset:(v_int props "container-relative-frame-inset") ?accessibility_identifier:(v_str props "accessibility-identifier") ?style_class:s.s_class ?on_appear:(ev "appear" emit props) ?text:(v_str props "text") ?icon:(icon_prop props "icon") ?selection_placement:(icon_placement_opt (v_str props "selection-placement")) ?variant:(variant_opt (v_str props "variant")) ?size:(control_size_opt (v_str props "size")) ?selected:(v_bool props "selected") ?checked:(v_bool props "checked") ?disabled:(v_bool props "disabled") ?on_press:(ev "press" emit props) ?tooltip:(v_str props "tooltip") ?shortcut_hint:(v_str props "shortcut-hint") ?font_size:(v_str props "font-size") ?font_weight:(v_int props "font-weight") ?font_family:(v_str props "font-family") ?font_style:(font_style_opt (v_str props "font-style")) ?line_height:(v_str props "line-height") ?letter_spacing:(v_float props "letter-spacing") ?text_decoration:(v_str props "text-decoration") ?white_space:(white_space_opt (v_str props "white-space")) ?text_overflow:(text_overflow_opt (v_str props "text-overflow")) ?overflow:(overflow_opt (v_str props "overflow")) ?hover_background:(v_str props "hover-background") ?hover_foreground:(v_str props "hover-foreground") ?focus_within_background:(v_str props "focus-within-background") ?focus_within_border:(v_str props "focus-within-border") ?focus_shadow:(v_str props "focus-shadow") ?transition:(v_str props "transition") (List.map (element ~emit) child_nodes) and build_toolbar_menu_trigger ~emit props child_nodes : E.toolbar_el = let s = sty_of props in @@ -999,7 +999,7 @@ E.toolbar_separator and build_dropdown_menu_item ~emit props child_nodes : E.dropdown_menu_item_el = let s = sty_of props in E.dropdown_menu_item - ?key:s.s_key ?gap:s.s_gap ?main:s.s_main ?cross:s.s_cross ?grow:s.s_grow ?padding:s.s_pad ?padding_horizontal:s.s_pad_h ?padding_vertical:s.s_pad_v ?margin:s.s_margin ?margin_horizontal:s.s_margin_h ?margin_vertical:s.s_margin_v ?margin_top:s.s_margin_top ?margin_right:s.s_margin_right ?margin_bottom:s.s_margin_bottom ?margin_left:s.s_margin_left ?background:s.s_bg ?foreground:s.s_fg ?border_color:s.s_border_color ?border_width:s.s_border_width ?corner_radius:s.s_radius ?width:s.s_width ?height:s.s_height ?min_width:s.s_min_width ?max_width:s.s_max_width ?min_height:s.s_min_height ?max_height:s.s_max_height ?container_relative_frame:(frame_axes_opt (v_str props "container-relative-frame")) ?container_relative_frame_inset:(v_int props "container-relative-frame-inset") ?accessibility_identifier:(v_str props "accessibility-identifier") ?style_class:s.s_class ?on_appear:(ev "appear" emit props) ?text:(v_str props "text") ?icon:(icon_prop props "icon") ?selection_placement:(icon_placement_opt (v_str props "selection-placement")) ?variant:(variant_opt (v_str props "variant")) ?size:(control_size_opt (v_str props "size")) ?selected:(v_bool props "selected") ?checked:(v_bool props "checked") ?disabled:(v_bool props "disabled") ?on_press:(ev "press" emit props) ?tooltip:(v_str props "tooltip") ?shortcut_hint:(v_str props "shortcut-hint") ?transition:(v_str props "transition") (List.map (element ~emit) child_nodes) + ?key:s.s_key ?gap:s.s_gap ?main:s.s_main ?cross:s.s_cross ?grow:s.s_grow ?padding:s.s_pad ?padding_horizontal:s.s_pad_h ?padding_vertical:s.s_pad_v ?margin:s.s_margin ?margin_horizontal:s.s_margin_h ?margin_vertical:s.s_margin_v ?margin_top:s.s_margin_top ?margin_right:s.s_margin_right ?margin_bottom:s.s_margin_bottom ?margin_left:s.s_margin_left ?background:s.s_bg ?foreground:s.s_fg ?border_color:s.s_border_color ?border_width:s.s_border_width ?corner_radius:s.s_radius ?width:s.s_width ?height:s.s_height ?min_width:s.s_min_width ?max_width:s.s_max_width ?min_height:s.s_min_height ?max_height:s.s_max_height ?container_relative_frame:(frame_axes_opt (v_str props "container-relative-frame")) ?container_relative_frame_inset:(v_int props "container-relative-frame-inset") ?accessibility_identifier:(v_str props "accessibility-identifier") ?style_class:s.s_class ?on_appear:(ev "appear" emit props) ?text:(v_str props "text") ?icon:(icon_prop props "icon") ?selection_placement:(icon_placement_opt (v_str props "selection-placement")) ?variant:(variant_opt (v_str props "variant")) ?size:(control_size_opt (v_str props "size")) ?selected:(v_bool props "selected") ?checked:(v_bool props "checked") ?disabled:(v_bool props "disabled") ?on_press:(ev "press" emit props) ?tooltip:(v_str props "tooltip") ?shortcut_hint:(v_str props "shortcut-hint") ?font_size:(v_str props "font-size") ?font_weight:(v_int props "font-weight") ?font_family:(v_str props "font-family") ?font_style:(font_style_opt (v_str props "font-style")) ?line_height:(v_str props "line-height") ?letter_spacing:(v_float props "letter-spacing") ?text_decoration:(v_str props "text-decoration") ?white_space:(white_space_opt (v_str props "white-space")) ?text_overflow:(text_overflow_opt (v_str props "text-overflow")) ?overflow:(overflow_opt (v_str props "overflow")) ?hover_background:(v_str props "hover-background") ?hover_foreground:(v_str props "hover-foreground") ?focus_within_background:(v_str props "focus-within-background") ?focus_within_border:(v_str props "focus-within-border") ?focus_shadow:(v_str props "focus-shadow") ?transition:(v_str props "transition") (List.map (element ~emit) child_nodes) and build_dropdown_menu_trigger ~emit props child_nodes : E.dropdown_menu_item_el = let s = sty_of props in diff --git a/src/lui_wire_schema.ml b/src/lui_wire_schema.ml index aefa12ac..7df1c95b 100644 --- a/src/lui_wire_schema.ml +++ b/src/lui_wire_schema.ml @@ -840,7 +840,7 @@ let view_contract = function | MenuItem -> Some { view_result = "t"; view_children = ViewList "t"; - view_properties = [(KeyValue, ViewString, false); (Gap, ViewInt, false); (MainAlignment, view_main_alignment, false); (CrossAlignment, view_cross_alignment, false); (GrowValue, ViewFloat, false); (PaddingValue, ViewInt, false); (PaddingHorizontal, ViewInt, false); (PaddingVertical, ViewInt, false); (MarginValue, ViewInt, false); (MarginHorizontal, ViewInt, false); (MarginVertical, ViewInt, false); (MarginTop, ViewInt, false); (MarginRight, ViewInt, false); (MarginBottom, ViewInt, false); (MarginLeft, ViewInt, false); (BackgroundValue, ViewString, false); (ForegroundValue, ViewString, false); (BorderColorValue, ViewString, false); (BorderWidth, ViewInt, false); (CornerRadius, ViewInt, false); (WidthValue, ViewInt, false); (HeightValue, ViewInt, false); (MinWidth, ViewInt, false); (MaxWidth, ViewInt, false); (MinHeight, ViewInt, false); (MaxHeight, ViewInt, false); (ContainerRelativeFrameValue, view_frame_axes, false); (ContainerRelativeFrameInset, ViewInt, false); (AccessibilityIdentifier, ViewString, false); (StyleClass, ViewString, false); (DataAttrs, ViewAttributes, false); (TextValue, ViewString, false); (InlineIconName, view_icon, false); (SelectionPlacementValue, view_icon_placement, false); (VariantValue, view_variant, false); (SizeValue, view_control_size, false); (Selected, ViewBool, false); (Checked, ViewBool, false); (Enabled, ViewBool, false); (TooltipText, ViewString, false); (TooltipKeys, ViewString, false); (Transition, ViewString, false); (AlignmentValue, view_alignment, false)]; + view_properties = [(KeyValue, ViewString, false); (Gap, ViewInt, false); (MainAlignment, view_main_alignment, false); (CrossAlignment, view_cross_alignment, false); (GrowValue, ViewFloat, false); (PaddingValue, ViewInt, false); (PaddingHorizontal, ViewInt, false); (PaddingVertical, ViewInt, false); (MarginValue, ViewInt, false); (MarginHorizontal, ViewInt, false); (MarginVertical, ViewInt, false); (MarginTop, ViewInt, false); (MarginRight, ViewInt, false); (MarginBottom, ViewInt, false); (MarginLeft, ViewInt, false); (BackgroundValue, ViewString, false); (ForegroundValue, ViewString, false); (BorderColorValue, ViewString, false); (BorderWidth, ViewInt, false); (CornerRadius, ViewInt, false); (WidthValue, ViewInt, false); (HeightValue, ViewInt, false); (MinWidth, ViewInt, false); (MaxWidth, ViewInt, false); (MinHeight, ViewInt, false); (MaxHeight, ViewInt, false); (ContainerRelativeFrameValue, view_frame_axes, false); (ContainerRelativeFrameInset, ViewInt, false); (AccessibilityIdentifier, ViewString, false); (StyleClass, ViewString, false); (DataAttrs, ViewAttributes, false); (TextValue, ViewString, false); (InlineIconName, view_icon, false); (SelectionPlacementValue, view_icon_placement, false); (VariantValue, view_variant, false); (SizeValue, view_control_size, false); (Selected, ViewBool, false); (Checked, ViewBool, false); (Enabled, ViewBool, false); (TooltipText, ViewString, false); (TooltipKeys, ViewString, false); (FontSize, ViewString, false); (FontWeight, ViewInt, false); (FontFamily, ViewString, false); (FontStyle, view_font_style, false); (LineHeight, ViewString, false); (LetterSpacing, ViewFloat, false); (TextDecoration, ViewString, false); (WhiteSpace, view_white_space, false); (TextOverflow, view_text_overflow, false); (Overflow, view_overflow, false); (HoverBackground, ViewString, false); (HoverForeground, ViewString, false); (FocusWithinBackground, ViewString, false); (FocusWithinBorder, ViewString, false); (FocusShadow, ViewString, false); (Transition, ViewString, false); (AlignmentValue, view_alignment, false)]; view_events = ["appear"; "pointer-enter"; "pointer-leave"; "press"; "press-modifiers"; "press-detail"; "pointer-down"; "pointer-up"; "context-menu"]; view_slots = []; } diff --git a/tooling/test/menu-item-style.test.mjs b/tooling/test/menu-item-style.test.mjs new file mode 100644 index 00000000..cf743a6e --- /dev/null +++ b/tooling/test/menu-item-style.test.mjs @@ -0,0 +1,143 @@ +import assert from 'node:assert/strict'; +import { mkdtempSync, writeFileSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { spawnSync } from 'node:child_process'; +import { fileURLToPath } from 'node:url'; +import test from 'node:test'; + +const root = fileURLToPath(new URL('../../', import.meta.url)); + +test('menu-item styling preserves slot capabilities and reactive properties', () => { + const dir = mkdtempSync(join(tmpdir(), 'lui-menu-style-')); + const run = args => spawnSync('opam', ['exec', '--', ...args], { cwd: root, encoding: 'utf8' }); + const success = args => { + const result = run(args); + assert.equal(result.status, 0, result.stdout + result.stderr); + }; + const props = [ + ['font_size', 'FontSize', '"14px"', 'StringValue "14px"'], + ['font_weight', 'FontWeight', '500', 'IntValue 500'], + ['font_family', 'FontFamily', '"sans-serif"', 'StringValue "sans-serif"'], + ['font_style', 'FontStyle', '`italic', 'StringValue "italic"'], + ['line_height', 'LineHeight', '"20px"', 'StringValue "20px"'], + ['letter_spacing', 'LetterSpacing', '0.5', 'FloatValue 0.5'], + ['text_decoration', 'TextDecoration', '"underline"', 'StringValue "underline"'], + ['white_space', 'WhiteSpace', '`nowrap', 'StringValue "nowrap"'], + ['text_overflow', 'TextOverflow', '`ellipsis', 'StringValue "ellipsis"'], + ['overflow', 'Overflow', '`hidden', 'StringValue "hidden"'], + ['hover_background', 'HoverBackground', '"red"', 'StringValue "red"'], + ['hover_foreground', 'HoverForeground', '"blue"', 'StringValue "blue"'], + ['focus_within_background', 'FocusWithinBackground', '"green"', 'StringValue "green"'], + ['focus_within_border', 'FocusWithinBorder', '"black"', 'StringValue "black"'], + ['focus_shadow', 'FocusShadow', '"inset 0 0 0 2px blue"', 'StringValue "inset 0 0 0 2px blue"'], + ]; + try { + success(['dune', 'build', 'ppx/lui_ppx.cmxa', 'src/lui.cmxa']); + writeFileSync(join(dir, 'driver.ml'), 'let () = Ppxlib.Driver.standalone ()\n'); + success(['ocamlfind', 'ocamlopt', '-package', 'ppxlib', '-linkpkg', '-linkall', + '_build/default/ppx/lui_ppx.cmxa', join(dir, 'driver.ml'), '-o', join(dir, 'driver')]); + const staticProps = props.map(([name, , value]) => `~${name}:(${value})`).join(' '); + const initial = { + font_size: ['"12px"', 'StringValue "12px"'], + font_weight: ['400', 'IntValue 400'], + font_family: ['"serif"', 'StringValue "serif"'], + font_style: ['`normal', 'StringValue "normal"'], + line_height: ['"18px"', 'StringValue "18px"'], + letter_spacing: ['0.25', 'FloatValue 0.25'], + text_decoration: ['"none"', 'StringValue "none"'], + white_space: ['`normal', 'StringValue "normal"'], + text_overflow: ['`clip', 'StringValue "clip"'], + overflow: ['`visible', 'StringValue "visible"'], + hover_background: ['"yellow"', 'StringValue "yellow"'], + hover_foreground: ['"white"', 'StringValue "white"'], + focus_within_background: ['"orange"', 'StringValue "orange"'], + focus_within_border: ['"gray"', 'StringValue "gray"'], + focus_shadow: ['"none"', 'StringValue "none"'], + }; + const reactiveProps = '~font_size:"999px" ' + props.map(([name, , value]) => + `~${name}:(reactive (fun active -> if active then ${value} else ${initial[name][0]}) source)`).join(' '); + const checks = props.map(([name, wire, , value]) => + `check label (property node ${wire} = Some (if reactive && not active then ${initial[name][1]} else ${value}));`).join('\n'); + const jsonProps = props.map(([name, , , wire]) => { + const value = wire.startsWith('StringValue') + ? `Lui_json_view.Str ${wire.slice('StringValue '.length)}` + : `Lui_json_view.Num ${Number(wire.split(' ')[1]).toFixed(1)}`; + return `("${name.replaceAll('_', '-')}", ${value})`; + }).join('; '); + writeFileSync(join(dir, 'probe.ml'), `open Lui_elements +open Lui_protocol +let batches = ref [] +let backend = {backend_profile = generic_profile (); + apply_batch = (fun batch -> batches := batch :: !batches; true)} +let ops () = List.concat_map (fun batch -> batch.ops) (List.rev !batches) +let check label condition = if not condition then failwith label +let node label = List.fold_left (fun result -> function + | SetProp (id, TextValue, StringValue value) when value = label -> id + | _ -> result) (-1) (ops ()) +let property node prop = List.fold_left (fun result -> function + | SetProp (id, key, value) when id = node && key = prop -> Some value + | _ -> result) None (ops ()) +let json_item label = Lui_json_view.Obj + (["kind", Lui_json_view.Str "menu-item"; "text", Lui_json_view.Str label] + @ [${jsonProps}]) +let json = Lui_json_view.Obj ["kind", Lui_json_view.Str "column"; + "children", Lui_json_view.Arr [json_item "json-ordinary"; + Lui_json_view.Obj ["kind", Lui_json_view.Str "toolbar"; + "label", Lui_json_view.Str "Actions"; + "children", Lui_json_view.Arr [json_item "json-toolbar"]]; + Lui_json_view.Obj ["kind", Lui_json_view.Str "dropdown-menu"; + "children", Lui_json_view.Arr [json_item "json-dropdown"]]]] +let view _ source _ = column [ + menu_item ~text:"static" ${staticProps} []; + menu_item ~text:"ordinary" ${reactiveProps} []; + toolbar ~label:"Actions" [toolbar_menu_item ~text:"toolbar" ${reactiveProps} []]; + dropdown_menu_view (dropdown_menu [ + dropdown_menu_item ~text:"dropdown" ${reactiveProps} []; + reactive_dropdown_menu_item (fun _ -> dropdown_menu_item ~text:"adapter" + ${staticProps} []) source; + dropdown_menu_item ~text:"default" []]); + dropdown_menu_view (dropdown_menu []); + Lui_json_view.render ~on_event:(fun ~id:_ ~kind:_ ~fields:_ -> ()) json] +let () = + let app = Lui_app.create backend false (fun _ value -> value) view in + check "start" (Lui_app.start app); + ignore (Lui_app.flush app); + let verify active = + List.iter (fun label -> let node = node label in check label (node >= 0); + let reactive = List.mem label ["ordinary"; "toolbar"; "dropdown"] in + ${checks} + ()) ["static"; "ordinary"; "toolbar"; "dropdown"; "adapter"; + "json-ordinary"; "json-toolbar"; "json-dropdown"]; + let node = node "default" in + check "default font untouched" (property node FontSize = None); + check "default hover untouched" (property node HoverBackground = None) + in + verify false; + let retained = node "dropdown" in + check "send" (Lui_app.send app true); + ignore (Lui_app.flush app); + check "retained node" (retained = node "dropdown"); + verify true; + check "dispose" (Lui_app.dispose app) +`); + const compile = ['ocamlfind', 'ocamlopt', '-package', 'ocaml-signal', '-linkpkg', + '-I', '_build/default/src/.lui.objs/byte', '-I', '_build/default/src/.lui.objs/native', + '_build/default/src/lui.cmxa', '-ppx', `${join(dir, 'driver')} --as-ppx`]; + success([...compile, join(dir, 'probe.ml'), '-o', join(dir, 'probe')]); + const executed = spawnSync(join(dir, 'probe'), [], { cwd: root, encoding: 'utf8' }); + assert.equal(executed.status, 0, executed.stdout + executed.stderr); + for (const expression of [ + 'dropdown_menu_item ~font_weight:"bold" []', + 'dropdown_menu_item ~font_style:`invalid []', + 'dropdown_menu [menu_item ~font_size:"14px" []]', + ]) { + writeFileSync(join(dir, 'invalid.ml'), `open Lui_elements\nlet _ = ${expression}\n`); + const result = run([...compile, '-c', join(dir, 'invalid.ml')]); + assert.notEqual(result.status, 0, expression); + assert.match(result.stderr, /Error:/); + } + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); From 5db8ea64845de99c3d7a8d158e77a3992be889c8 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 20 Nov 2026 03:05:59 -0800 Subject: [PATCH 02/12] Document renderer limits for menu-item styling --- docs/api-migrations.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/api-migrations.md b/docs/api-migrations.md index 5626aa3e..e99924ea 100644 --- a/docs/api-migrations.md +++ b/docs/api-migrations.md @@ -30,6 +30,25 @@ The language-neutral menu-item view contract includes these properties too. This exposes existing wire properties only; the wire vocabulary, admission tables, backend defaults and event behavior are unchanged. +These are wire-level properties, not a promise of identical native menu +styling on every renderer: + +- Web applies the typography and interaction properties to menu-item DOM + nodes through its text styles and appearance channels. +- SDL/native applies them through its common text and appearance renderer + (`platform/native/lui_paint`), independently of OS-native menus. +- Apple SwiftUI native menus keep platform menu-label typography. + `LUINativeMenuActions.itemLabel(for:)` builds a native `Label`/`Text` without applying + the item's typography or hover/focus overrides. +- Android Material menu rows keep their native typography and state chrome. + `LuiMenuItem` derives text style from Material/style classes rather than + the item's typography properties, and neither it nor `luiChrome` consumes + the hover/focus overrides. + +The new menu-label typography and interaction overrides are currently drawn +by Web and SDL/native only. Apple and Android still receive the properties; +applications must not rely on them changing native menu labels there. + ### Apple row intrinsic text priority Non-growing `text`, `heading`, and `paragraph` children in Apple rows now From 8441bc09350efc0394f77a26da3584e46ba186a9 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 20 Nov 2026 03:11:03 -0800 Subject: [PATCH 03/12] Honor independent menu-item appearance overrides --- docs/api-migrations.md | 10 +++ platform/web/src/lui.css | 21 +++--- platform/web/test/appearance.e2e.mjs | 68 +++++++++++++++++++ .../test/fixtures/appearance-regression.html | 20 +++++- platform/web/test/tailwind.test.mjs | 2 +- 5 files changed, 108 insertions(+), 13 deletions(-) diff --git a/docs/api-migrations.md b/docs/api-migrations.md index e99924ea..42080dae 100644 --- a/docs/api-migrations.md +++ b/docs/api-migrations.md @@ -49,6 +49,16 @@ The new menu-label typography and interaction overrides are currently drawn by Web and SDL/native only. Apple and Android still receive the properties; applications must not rely on them changing native menu labels there. +Web's default menu highlight honors each authored appearance channel +independently. A foreground-only hover override preserves the default +highlight background; a focus-background-only override wins on keyboard +focus without requiring a hover background: + +```ocaml +dropdown_menu_item ~text:"Open" ~hover_foreground:"red" [] +dropdown_menu_item ~text:"Save" ~focus_within_background:"muted" [] +``` + ### Apple row intrinsic text priority Non-growing `text`, `heading`, and `paragraph` children in Apple rows now diff --git a/platform/web/src/lui.css b/platform/web/src/lui.css index c7d8f977..0038d259 100644 --- a/platform/web/src/lui.css +++ b/platform/web/src/lui.css @@ -2599,30 +2599,29 @@ body { border-color: var(--lui-focus-within-border, var(--lui-current-hover-border, revert-layer)); } - /* Default menu highlight is the Base UI inverted row. An authored - hover-background stays in the inline style and keeps the ordinary - fallback text color, so a custom light highlight does not turn white. */ + /* Default menu highlight is the Base UI inverted row. Each authored + appearance channel overrides its own fallback independently. */ .lui-menu-item:is([data-highlighted], :focus-visible):not(:disabled, [data-disabled], [aria-disabled="true"], [style*="--lui-hover-bg"]) { - background-color: var(--lui-foreground); - color: var(--lui-background); + background-color: var(--lui-current-focus-within-bg, var(--lui-foreground)); + color: var(--lui-current-hover-fg, var(--lui-background)); } @media (hover: hover) { .lui-menu-item:hover:not(:disabled, [data-disabled], [aria-disabled="true"], [style*="--lui-hover-bg"]) { - background-color: var(--lui-foreground); - color: var(--lui-background); + background-color: var(--lui-current-focus-within-bg, var(--lui-foreground)); + color: var(--lui-current-hover-fg, var(--lui-background)); } } .lui-menu-item[data-variant="destructive"]:is([data-highlighted], :focus-visible):not(:disabled, [data-disabled], [aria-disabled="true"], [style*="--lui-hover-bg"]) { - background-color: var(--color-destructive); - color: var(--color-destructive-foreground); + background-color: var(--lui-current-focus-within-bg, var(--color-destructive)); + color: var(--lui-current-hover-fg, var(--color-destructive-foreground)); } @media (hover: hover) { .lui-menu-item[data-variant="destructive"]:hover:not(:disabled, [data-disabled], [aria-disabled="true"], [style*="--lui-hover-bg"]) { - background-color: var(--color-destructive); - color: var(--color-destructive-foreground); + background-color: var(--lui-current-focus-within-bg, var(--color-destructive)); + color: var(--lui-current-hover-fg, var(--color-destructive-foreground)); } } diff --git a/platform/web/test/appearance.e2e.mjs b/platform/web/test/appearance.e2e.mjs index 3897a21f..acaf1028 100644 --- a/platform/web/test/appearance.e2e.mjs +++ b/platform/web/test/appearance.e2e.mjs @@ -183,6 +183,74 @@ test("explicit base appearance composes with hover, press, selection and disable assert.equal((await read()).opacity, '0.9') }) +test("menu hover channels override their defaults independently", async () => { + await page.goto(`${origin}/platform/web/test/fixtures/appearance-regression.html`) + await page.mouse.move(1250, 850) + const variants = await page.evaluate(() => window.probe.menuItems) + for (const items of Object.values(variants)) { + const baseline = page.locator(`#lui-node-${items.baseline}`) + const ordinaryInk = await baseline.evaluate(el => getComputedStyle(el).color) + await baseline.hover() + const defaultHighlight = await baseline.evaluate(el => getComputedStyle(el).backgroundColor) + const background = page.locator(`#lui-node-${items.hoverBg}`) + await background.hover() + assert.deepEqual(await background.evaluate(el => ({ + background: getComputedStyle(el).backgroundColor, + color: getComputedStyle(el).color, + })), { background: "rgb(18, 52, 86)", color: ordinaryInk }) + const foreground = page.locator(`#lui-node-${items.hoverFg}`) + await foreground.hover() + assert.deepEqual(await foreground.evaluate(el => ({ + background: getComputedStyle(el).backgroundColor, + color: getComputedStyle(el).color, + })), { background: defaultHighlight, color: "rgb(18, 52, 86)" }) + await page.evaluate(id => { + window.probe.unset(id, "hover-foreground") + window.probe.flush() + }, items.hoverFg) + assert.notEqual(await foreground.evaluate(el => getComputedStyle(el).color), "rgb(18, 52, 86)") + } +}) + +test("menu focus channels override their defaults independently", async () => { + await page.goto(`${origin}/platform/web/test/fixtures/appearance-regression.html`) + await page.mouse.move(1250, 850) + await page.keyboard.press("Tab") + const variants = await page.evaluate(() => window.probe.menuItems) + for (const items of Object.values(variants)) { + const baseline = page.locator(`#lui-node-${items.baseline}`) + await baseline.focus() + const defaultHighlight = await baseline.evaluate(el => getComputedStyle(el).backgroundColor) + const background = page.locator(`#lui-node-${items.focusBg}`) + await background.focus() + assert.equal(await background.evaluate(el => el.matches(":focus-visible")), true) + assert.equal(await background.evaluate(el => getComputedStyle(el).backgroundColor), "rgb(18, 52, 86)") + await page.evaluate(id => { + window.probe.unset(id, "focus-within-background") + window.probe.flush() + }, items.focusBg) + assert.equal(await background.evaluate(el => getComputedStyle(el).backgroundColor), defaultHighlight) + const border = page.locator(`#lui-node-${items.focusBorder}`) + await border.focus() + assert.equal(await border.evaluate(el => getComputedStyle(el).borderTopColor), "rgb(18, 52, 86)") + const shadow = page.locator(`#lui-node-${items.focusShadow}`) + await shadow.focus() + assert.match(await shadow.evaluate(el => getComputedStyle(el).boxShadow), /^rgb\(18, 52, 86\) 0px 0px 0px 2px$/) + } +}) + +test("disabled menu items ignore authored hover channels", async () => { + await page.goto(`${origin}/platform/web/test/fixtures/appearance-regression.html`) + await page.mouse.move(1250, 850) + const variants = await page.evaluate(() => window.probe.menuItems) + for (const items of Object.values(variants)) { + const item = page.locator(`#lui-node-${items.disabled}`) + const ordinaryInk = await item.evaluate(el => getComputedStyle(el).color) + await item.hover({ force: true }) + assert.equal(await item.evaluate(el => getComputedStyle(el).color), ordinaryInk) + } +}) + test('retained button content preserves owned slots and intrinsic spacing', async () => { await page.goto(`${origin}/platform/web/test/fixtures/button-content-regression.html`) await page.getByRole('button', {name: 'Audit retained content', exact: true}).click() diff --git a/platform/web/test/fixtures/appearance-regression.html b/platform/web/test/fixtures/appearance-regression.html index ad233661..7134aa5a 100644 --- a/platform/web/test/fixtures/appearance-regression.html +++ b/platform/web/test/fixtures/appearance-regression.html @@ -17,6 +17,7 @@ body { margin: 24px; font: 16px system-ui } #host { max-width: 720px } #host .lui-button { transition: none } +#host .lui-menu-item { transition: none }