@@ -745,13 +745,21 @@ void Send()
745745 : Localized ( "Chat_Composer_Tooltip_Send" , "Send" ) ;
746746 var controlCornerRadius = new CornerRadius ( 4 ) ;
747747
748- Element IconButton ( string glyph , string automationName , Action onClick , bool enabled = true )
748+ Element IconButton (
749+ string glyph ,
750+ string automationName ,
751+ Action onClick ,
752+ bool enabled = true ,
753+ string ? automationId = null )
749754 {
750755 return Button (
751756 TextBlock ( glyph ) . Set ( textBlock =>
752757 {
753758 textBlock . FontFamily = FluentIconCatalog . SymbolThemeFontFamily ;
754759 textBlock . FontSize = 16 ;
760+ Microsoft . UI . Xaml . Automation . AutomationProperties . SetAccessibilityView (
761+ textBlock ,
762+ Microsoft . UI . Xaml . Automation . Peers . AccessibilityView . Raw ) ;
755763 } ) ,
756764 onClick )
757765 . AutomationName ( automationName )
@@ -773,11 +781,25 @@ Element IconButton(string glyph, string automationName, Action onClick, bool ena
773781 button . CornerRadius = controlCornerRadius ;
774782 button . IsEnabled = enabled ;
775783 button . BorderThickness = new Thickness ( 0 ) ;
784+ if ( ! string . IsNullOrWhiteSpace ( automationId ) )
785+ {
786+ Microsoft . UI . Xaml . Automation . AutomationProperties . SetAutomationId (
787+ button ,
788+ automationId ) ;
789+ }
790+ ComposerAutomationVisibility . Prepare ( button ) ;
776791 ToolTipService . SetToolTip ( button , automationName ) ;
777- } ) ;
792+ } )
793+ . OnUnmount ( control => ComposerAutomationVisibility . Detach (
794+ ( FrameworkElement ) control ) ) ;
778795 }
779796
780- Element PickerButton ( string label , string automationName , bool enabled , double maxLabelWidth )
797+ Element PickerButton (
798+ string label ,
799+ string automationName ,
800+ string automationId ,
801+ bool enabled ,
802+ double maxLabelWidth )
781803 {
782804 return Button (
783805 HStack (
@@ -794,6 +816,9 @@ Element PickerButton(string label, string automationName, bool enabled, double m
794816 textBlock . FontFamily = FluentIconCatalog . SymbolThemeFontFamily ;
795817 textBlock . FontSize = 10 ;
796818 textBlock . Margin = new Thickness ( 2 , 4 , 0 , 0 ) ;
819+ Microsoft . UI . Xaml . Automation . AutomationProperties . SetAccessibilityView (
820+ textBlock ,
821+ Microsoft . UI . Xaml . Automation . Peers . AccessibilityView . Raw ) ;
797822 } ) ) ,
798823 ( ) => { } )
799824 . AutomationName ( automationName )
@@ -814,7 +839,13 @@ Element PickerButton(string label, string automationName, bool enabled, double m
814839 button . CornerRadius = controlCornerRadius ;
815840 button . IsEnabled = enabled ;
816841 button . BorderThickness = new Thickness ( 0 ) ;
817- } ) ;
842+ Microsoft . UI . Xaml . Automation . AutomationProperties . SetAutomationId (
843+ button ,
844+ automationId ) ;
845+ ComposerAutomationVisibility . Prepare ( button ) ;
846+ } )
847+ . OnUnmount ( control => ComposerAutomationVisibility . Detach (
848+ ( FrameworkElement ) control ) ) ;
818849 }
819850
820851 var attachmentRows = props . PendingAttachments
@@ -1122,6 +1153,7 @@ void CommitSlashText(string value, ReactorSlashMenuState nextState)
11221153 control . Resources [ "TextControlBorderBrush" ] = transparent ;
11231154 control . Resources [ "TextControlBorderBrushFocused" ] = transparent ;
11241155 control . Resources [ "TextControlBorderBrushPointerOver" ] = transparent ;
1156+ ComposerAutomationVisibility . Prepare ( control ) ;
11251157 } )
11261158 . OnMount ( control =>
11271159 {
@@ -1136,6 +1168,7 @@ void CommitSlashText(string value, ReactorSlashMenuState nextState)
11361168 var textBox = ( TextBox ) control ;
11371169 textBox . Paste -= pasteHandler . Current ;
11381170 textBox . ContextFlyout = null ;
1171+ ComposerAutomationVisibility . Detach ( textBox ) ;
11391172 } ) ;
11401173 UseEffect ( ( Func < Action > ) ( ( ) =>
11411174 {
@@ -1150,6 +1183,7 @@ void CommitSlashText(string value, ReactorSlashMenuState nextState)
11501183 PickerButton (
11511184 props . CurrentThread . Title ,
11521185 $ "{ Localized ( "Chat_Composer_Accessibility_Session" , "Session" ) } : { props . CurrentThread . Title } ",
1186+ "ChatComposerSessionPicker" ,
11531187 ! props . MessageOptionsDisabled && props . AvailableChannels . Count > 1 ,
11541188 props . IsCompact ? 56 : 160 ) ,
11551189 props . AvailableChannels
@@ -1167,6 +1201,7 @@ void CommitSlashText(string value, ReactorSlashMenuState nextState)
11671201 PickerButton (
11681202 modelPickerLabel ,
11691203 $ "{ Localized ( "Chat_Composer_Accessibility_Model" , "Model" ) } : { modelPickerLabel } ",
1204+ "ChatComposerModelPicker" ,
11701205 ! props . MessageOptionsDisabled ,
11711206 props . IsCompact ? 68 : 180 ) ,
11721207 modelNames
@@ -1187,6 +1222,7 @@ void CommitSlashText(string value, ReactorSlashMenuState nextState)
11871222 PickerButton (
11881223 ThinkingLevels [ thinkingIndex ] ,
11891224 $ "{ Localized ( "Chat_Composer_Accessibility_Reasoning" , "Reasoning" ) } : { ThinkingLevels [ thinkingIndex ] } ",
1225+ "ChatComposerReasoningPicker" ,
11901226 ! props . MessageOptionsDisabled ,
11911227 props . IsCompact ? 54 : 96 ) ,
11921228 ThinkingLevels
@@ -1201,7 +1237,8 @@ void CommitSlashText(string value, ReactorSlashMenuState nextState)
12011237 "\uE723 " ,
12021238 Localized ( "Chat_Composer_Tooltip_Attach" , "Attach" ) ,
12031239 ( ) => props . OnAttachClick ? . Invoke ( ) ,
1204- props . OnAttachClick is not null ) ;
1240+ props . OnAttachClick is not null ,
1241+ "ChatComposerAttach" ) ;
12051242 var voiceButton = IconButton (
12061243 isRecording
12071244 ? "\uE15B "
@@ -1219,25 +1256,35 @@ void CommitSlashText(string value, ReactorSlashMenuState nextState)
12191256 else
12201257 StartVoiceRecording ( ) ;
12211258 } ,
1222- props . OnVoiceRequest is not null ) ;
1259+ props . OnVoiceRequest is not null ,
1260+ "ChatComposerVoice" ) ;
12231261 var speakerButton = IconButton (
12241262 props . IsSpeakerMuted ? "\uE74F " : "\uE767 " ,
12251263 props . IsSpeakerMuted ? "Unmute" : "Mute" ,
1226- props . OnSpeakerToggle ) ;
1264+ props . OnSpeakerToggle ,
1265+ automationId : "ChatComposerSpeakerToggle" ) ;
12271266 Element settingsButton = props . IsCompact || props . OnSettingsClick is null
12281267 ? Empty ( )
12291268 : IconButton (
12301269 "\uE713 " ,
12311270 Localized ( "Chat_Composer_Tooltip_Settings" , "Settings" ) ,
1232- props . OnSettingsClick ) ;
1271+ props . OnSettingsClick ,
1272+ automationId : "ChatComposerSettings" ) ;
12331273
12341274 Element primaryAction = props . TurnActive
1235- ? IconButton ( "\uE71A " , actionLabel , props . OnStop )
1275+ ? IconButton (
1276+ "\uE71A " ,
1277+ actionLabel ,
1278+ props . OnStop ,
1279+ automationId : "ChatComposerPrimaryAction" )
12361280 : Button (
12371281 TextBlock ( "\uE724 " ) . Set ( textBlock =>
12381282 {
12391283 textBlock . FontFamily = FluentIconCatalog . SymbolThemeFontFamily ;
12401284 textBlock . FontSize = 16 ;
1285+ Microsoft . UI . Xaml . Automation . AutomationProperties . SetAccessibilityView (
1286+ textBlock ,
1287+ Microsoft . UI . Xaml . Automation . Peers . AccessibilityView . Raw ) ;
12411288 } ) ,
12421289 Send )
12431290 . AccentButton ( )
@@ -1250,12 +1297,18 @@ void CommitSlashText(string value, ReactorSlashMenuState nextState)
12501297 button . MinHeight = 32 ;
12511298 button . Padding = new Thickness ( 0 ) ;
12521299 button . CornerRadius = controlCornerRadius ;
1300+ Microsoft . UI . Xaml . Automation . AutomationProperties . SetAutomationId (
1301+ button ,
1302+ "ChatComposerPrimaryAction" ) ;
12531303 button . IsEnabled = props . ConnectionState == "connected"
12541304 && ! isSending
12551305 && ! slashDisplay . IsLoading
12561306 && ( ! string . IsNullOrWhiteSpace ( text ) || props . PendingAttachments . Count > 0 ) ;
1307+ ComposerAutomationVisibility . Prepare ( button ) ;
12571308 ToolTipService . SetToolTip ( button , actionLabel ) ;
1258- } ) ;
1309+ } )
1310+ . OnUnmount ( control => ComposerAutomationVisibility . Detach (
1311+ ( FrameworkElement ) control ) ) ;
12591312
12601313 var leftToolbar = HStack ( 8 , attachButton , sessionPicker , modelPicker , reasoningPicker )
12611314 . HAlign ( HorizontalAlignment . Left )
@@ -1906,3 +1959,66 @@ private static string Localized(string key, string fallback)
19061959 : value ;
19071960 }
19081961}
1962+
1963+ internal static class ComposerAutomationVisibility
1964+ {
1965+ public static void Prepare ( FrameworkElement control )
1966+ {
1967+ Detach ( control ) ;
1968+ if ( HasUsableLayout ( control ) )
1969+ {
1970+ ApplyReadyState ( control ) ;
1971+ return ;
1972+ }
1973+
1974+ control . IsHitTestVisible = false ;
1975+ Microsoft . UI . Xaml . Automation . AutomationProperties . SetAccessibilityView (
1976+ control ,
1977+ Microsoft . UI . Xaml . Automation . Peers . AccessibilityView . Raw ) ;
1978+ control . Loaded += OnLoaded ;
1979+ control . SizeChanged += OnSizeChanged ;
1980+ }
1981+
1982+ public static void Detach ( FrameworkElement control )
1983+ {
1984+ control . Loaded -= OnLoaded ;
1985+ control . SizeChanged -= OnSizeChanged ;
1986+ }
1987+
1988+ private static void OnLoaded ( object sender , RoutedEventArgs args ) =>
1989+ TryEnableHitTesting ( sender ) ;
1990+
1991+ private static void OnSizeChanged ( object sender , SizeChangedEventArgs args ) =>
1992+ TryEnableHitTesting ( sender ) ;
1993+
1994+ private static void TryEnableHitTesting ( object sender )
1995+ {
1996+ if ( sender is not FrameworkElement control || ! HasUsableLayout ( control ) )
1997+ return ;
1998+
1999+ ApplyReadyState ( control ) ;
2000+ }
2001+
2002+ private static void ApplyReadyState ( FrameworkElement control )
2003+ {
2004+ Microsoft . UI . Xaml . Automation . AutomationProperties . SetAccessibilityView (
2005+ control ,
2006+ Microsoft . UI . Xaml . Automation . Peers . AccessibilityView . Control ) ;
2007+ control . IsHitTestVisible = true ;
2008+ var peer = Microsoft . UI . Xaml . Automation . Peers . FrameworkElementAutomationPeer
2009+ . FromElement ( control )
2010+ ?? Microsoft . UI . Xaml . Automation . Peers . FrameworkElementAutomationPeer
2011+ . CreatePeerForElement ( control ) ;
2012+ peer ? . RaisePropertyChangedEvent (
2013+ Microsoft . UI . Xaml . Automation . AutomationElementIdentifiers . IsOffscreenProperty ,
2014+ true ,
2015+ false ) ;
2016+ Detach ( control ) ;
2017+ }
2018+
2019+ private static bool HasUsableLayout ( FrameworkElement control ) =>
2020+ control . IsLoaded
2021+ && control . Visibility == Visibility . Visible
2022+ && control . ActualWidth > 0
2023+ && control . ActualHeight > 0 ;
2024+ }
0 commit comments