Commit 93c2623e authored by Mihai Branescu's avatar Mihai Branescu
Browse files

For #8060 - make `BrowserMenuImageSwitch` highlight the entire row for a11y

Fixed by making the switch not important for accessibility, and making the parent view forward the click event instead
parent 1d5e94f0
......@@ -8,7 +8,6 @@ import android.content.Context
import android.view.View
import androidx.annotation.DrawableRes
import androidx.annotation.VisibleForTesting
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.SwitchCompat
import mozilla.components.browser.menu.BrowserMenu
import mozilla.components.browser.menu.R
......@@ -35,13 +34,13 @@ class BrowserMenuImageSwitch(
override fun getLayoutResource(): Int = R.layout.mozac_browser_menu_item_image_switch
override fun bind(menu: BrowserMenu, view: View) {
super.bind(menu, view.findViewById<SwitchCompat>(R.id.switch_widget))
bindImage(view)
super.bind(menu, view)
bindImage(view as SwitchCompat)
}
private fun bindImage(view: View) {
val imageView = view.findViewById<AppCompatImageView>(R.id.image)
imageView.setImageResource(imageResource)
private fun bindImage(switch: SwitchCompat) {
switch.setCompoundDrawablesWithIntrinsicBounds(
imageResource, 0, 0, 0)
}
override fun asCandidate(context: Context) = super.asCandidate(context).copy(
......
<?xml version="1.0" encoding="utf-8"?><!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/Mozac.Browser.Menu.Item.Container"
<androidx.appcompat.widget.SwitchCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/switch_widget"
style="@style/Mozac.Browser.Menu.Item.Text"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal">
android:layout_height="@dimen/mozac_browser_menu_item_container_layout_height"
android:drawablePadding="@dimen/mozac_browser_menu_item_image_text_icon_padding"
android:paddingStart="@dimen/mozac_browser_menu_item_container_padding_start"
android:paddingEnd="@dimen/mozac_browser_menu_item_container_padding_end"
android:textAlignment="viewStart"
app:drawableStartCompat="@android:drawable/screen_background_dark" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image"
style="@style/Mozac.Browser.Menu.Item.ImageText.Icon"
android:background="@android:color/transparent"
android:clickable="false"
android:importantForAccessibility="no"
tools:src="@android:drawable/screen_background_dark" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_widget"
style="@style/Mozac.Browser.Menu.Item.Text"
android:textAlignment="viewStart"
android:layout_width="match_parent"
android:layout_height="@dimen/mozac_browser_menu_item_container_layout_height"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:orientation="vertical"
android:paddingStart="@dimen/mozac_browser_menu_item_image_text_label_padding_start"
android:paddingEnd="0dp"/>
</LinearLayout>
......@@ -48,6 +48,7 @@
<!--Icon-->
<dimen name="mozac_browser_menu_item_image_text_icon_width">24dp</dimen>
<dimen name="mozac_browser_menu_item_image_text_icon_height">24dp</dimen>
<dimen name="mozac_browser_menu_item_image_text_icon_padding">20dp</dimen>
<!--Icon-->
<!--Label-->
......
......@@ -32,6 +32,9 @@ permalink: /changelog/
* **browser-menu**
* ⚠️ **This is a breaking change**: Removed `SimpleBrowserMenuHighlightableItem.itemType`. Use a WeakMap instead if you need to attach private data.
* **browser-menu**
* For a11y, `BrowserMenuImageSwitch` now highlights the entire row, not just the switch
# 53.0.0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment