Skip to content

Commit

Permalink
Fix screen readers trying to read IconElement in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Sep 24, 2024
1 parent 35d3b8c commit 7969f43
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Wpf.Ui/Controls/Button/Button.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
TextElement.Foreground="{TemplateBinding Foreground}" />

<!-- TextBlock added so that screen readers don't try to read Icon -->
<TextBlock
Grid.Column="0"
Grid.ColumnSpan="2"
Width="{Binding Width, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
Margin="-10"
FontSize="1"
Opacity="0"
Text="{Binding AutomationProperties.Name, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
Height="{Binding Height, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
Background="Black"/>
</Grid>
</Border>
</Border>
Expand Down
42 changes: 42 additions & 0 deletions src/Wpf.Ui/Controls/Menu/MenuItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
ContentSource="Header"
RecognizesAccessKey="True"
TextElement.Foreground="{TemplateBinding Foreground}" />
<!-- TextBlock added so that screen readers don't try to read Icon -->
<TextBlock Grid.Column="0"
Grid.ColumnSpan="3"
Width="{Binding Width, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Height="{Binding Height, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Margin="-10"
FontSize="1"
Opacity="0"
Text="{Binding AutomationProperties.Name, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Background="Black"/>
</Grid>

<Popup
Expand Down Expand Up @@ -181,6 +191,16 @@
ContentSource="Header"
RecognizesAccessKey="True"
TextElement.Foreground="{TemplateBinding Foreground}" />
<!-- TextBlock added so that screen readers don't try to read Icon -->
<TextBlock Grid.Column="0"
Grid.ColumnSpan="3"
Width="{Binding Width, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Height="{Binding Height, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Margin="-10"
FontSize="1"
Opacity="0"
Text="{Binding AutomationProperties.Name, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Background="Black"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
Expand Down Expand Up @@ -264,6 +284,17 @@
FontSize="11"
Foreground="{DynamicResource TextFillColorDisabledBrush}"
Text="{TemplateBinding InputGestureText}" />

<!-- TextBlock added so that screen readers don't try to read Icon -->
<TextBlock Grid.Column="0"
Grid.ColumnSpan="5"
Width="{Binding Width, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Height="{Binding Height, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Margin="-10"
FontSize="1"
Opacity="0"
Text="{Binding AutomationProperties.Name, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Background="Black"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
Expand Down Expand Up @@ -334,6 +365,17 @@
FontSize="{TemplateBinding FontSize}"
Symbol="ChevronRight20" />
</Grid>

<!-- Fix double narration from mousing over the button and then the associated text -->
<TextBlock Grid.Column="0"
Grid.ColumnSpan="3"
Width="{Binding Width, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Height="{Binding Height, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Margin="-10"
FontSize="1"
Opacity="0"
Text="{Binding AutomationProperties.Name, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"
Background="Black"/>
</Grid>
</Border>

Expand Down

0 comments on commit 7969f43

Please sign in to comment.