Skip to content

[ChipGroup] Ignores importantForAccessibility #4946

@nikclayton

Description

@nikclayton

Description: ChipGroup ignores the android:importantForAccessibility attribute.

Expected behavior: If set, the attribute should be honoured.

I'm using a ChipGroup to display labels associated with some content. The user does not directly interact with the chips (i.e., tapping them does nothing).

In addition, the parent layout that contains the ChipGroup provides a contentDescription that includes a description of the visible chips, and provides a set of accessibility actions to allow the user to interact with the content.

Because of this, the ChipGroup, and the chips within, are unimportant for accessibility, and they should not be tappable if e.g., the user has TalkBack enabled and taps on one of the chips -- the parent layout should be selected.

This:

<com.google.android.material.chip.ChipGroup
    android:id="@+id/someId"
    ...
    android:importantForAccessibility="no" />

doesn't work, because the ChipGroup constructor ignores the attribute and explicitly sets the importantForAccessibility property to IMPORTANT_FOR_ACCESSIBILITY_YES.

It's fine for this to be the default, but if it's overridden in the layout that should be respected.

The fix is to add android:importantForAccessibility to lib/java/com/google/android/material/chip/res/values/attrs.xml, and then modify the ChipGroup constructor to fetch this value (defaulting to IMPORTANT_FOR_ACCESSIBILITY_YES) and set the value.

Source code:

setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);

Android API version: Android API version here

Material Library version: 1.14.0-alpha05 (it's present in the master branch at the time of writing, and that's the most recent release).

Device: N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions