material-components / material-components/material-components-android

[MaterialButton] Padding is incorrect when using `iconGravity` is `end`/`textEnd`

Open
#3,502 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Widget: Button
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Description:** `MaterialButton` supports moving the icon to the end of the button or the button text by setting `iconGravity` to `end` or `textEnd`. The padding that `Widget.Material3.Button.Icon` adds however assumes the icon is at the start of the start of the text of the button (`start` or `textStart`). As an example, here's a button using `Widget.Material3.Button.Icon` with `iconGravity` set to `textEnd`:

Screenshot 2023-08-01 at 17 23 13

**Expected behavior:** It would be amazing if `MaterialButton` (or the `Widget.Material3.Button.x` styles) were able to dynamically switch the padding based on the `iconGravity`, but I'm not sure how feasible that is. Alternatively, MaterialComponents could provide a style (or a theme overlay) for end icons like:

```xml

<item name="android:paddingStart">@dimen/m3_btn_icon_btn_padding_right</item>
<item name="android:paddingEnd">@dimen/m3_btn_icon_btn_padding_left</item>
<item name="iconGravity">end</item>

```

**Material Library version:** 1.9.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at MaterialButton and the Widget.Material3.Button.Icon style resources; compare how padding is assigned for iconGravity start/textStart versus end/textEnd. Reproduce the shown textEnd layout and verify the resulting button padding for both end modes, with coverage if the existing component tests cover these styles.

Written by the indexing model from the issue text.

Assessment

Tech stack
android
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.