Skip to content

Commit

Permalink
[FloatingActionButton] Add an accessibility role to FloatingActionBut…
Browse files Browse the repository at this point in the history
…ton and ExtendedFloatingActionButton.

PiperOrigin-RevId: 663363115
  • Loading branch information
Material Design Team authored and imhappi committed Aug 16, 2024
1 parent da0b738 commit f3aacd7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ public void setPadding(int left, int top, int right, int bottom) {
}
}

@Override
public CharSequence getAccessibilityClassName() {
return FloatingActionButton.ACCESSIBIILTY_FAB_ROLE;
}

/**
* Add a listener that will be invoked when this ExtendedFloatingActionButton is shown. See {@link
* AnimatorListener}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class FloatingActionButton extends VisibilityAwareImageButton
Shapeable,
CoordinatorLayout.AttachedBehavior {

static final String ACCESSIBIILTY_FAB_ROLE =
"com.google.android.material.floatingactionbutton.FloatingActionButton";
private static final String LOG_TAG = "FloatingActionButton";
private static final String EXPANDABLE_WIDGET_HELPER_KEY = "expandableWidgetHelper";
private static final int DEF_STYLE_RES = R.style.Widget_Design_FloatingActionButton;
Expand Down Expand Up @@ -936,6 +938,11 @@ public boolean onTouchEvent(@NonNull MotionEvent ev) {
return super.onTouchEvent(ev);
}

@Override
public CharSequence getAccessibilityClassName() {
return ACCESSIBIILTY_FAB_ROLE;
}

/**
* Behavior designed for use with {@link FloatingActionButton} instances. Its main function is to
* move {@link FloatingActionButton} views so that any displayed {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static com.google.android.material.testutils.TestUtilsMatchers.withFabContentHeight;
import static com.google.android.material.testutils.TestUtilsMatchers.withFabCustomSize;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -309,4 +310,12 @@ public void testSetCustomSize() {
.perform(setCustomSize(20))
.check(matches(withFabCustomSize(20)));
}

@Test
@SmallTest
public void testA11yClassName() {
FloatingActionButton fab = activityTestRule.getActivity().findViewById(R.id.fab_standard);
assertEquals(
FloatingActionButton.ACCESSIBIILTY_FAB_ROLE, fab.getAccessibilityClassName().toString());
}
}

0 comments on commit f3aacd7

Please sign in to comment.