Skip to content

Commit c713b9b

Browse files
docs(material/button): document iconPositionEnd and matButtonIcon attributes (#32822)
Add an "Icon positioning" section to the button documentation explaining how icons are projected within buttons using content projection selectors: - Default behavior: icons appear before the label - iconPositionEnd: places an icon after the label - matButtonIcon: marks custom elements for icon projection These attributes have been supported since the MDC migration but were never documented. Closes #26259
1 parent 1ef3463 commit c713b9b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/material/button/button.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,47 @@ the `extended` attribute, mini FABs do not.
4343
</button>
4444
```
4545

46+
### Icon positioning
47+
48+
Buttons can contain icons alongside text. By default, icons (`mat-icon`, `.material-icons`, or
49+
elements with the `matButtonIcon` attribute) are projected **before** the button label.
50+
51+
```html
52+
<button matButton>
53+
<mat-icon>favorite</mat-icon>
54+
Like
55+
</button>
56+
```
57+
58+
To place an icon **after** the button label, add the `iconPositionEnd` attribute to the icon element:
59+
60+
```html
61+
<button matButton>
62+
Send
63+
<mat-icon iconPositionEnd>send</mat-icon>
64+
</button>
65+
```
66+
67+
You can also use both positions at once:
68+
69+
```html
70+
<button matButton>
71+
<mat-icon>arrow_back</mat-icon>
72+
Navigate
73+
<mat-icon iconPositionEnd>arrow_forward</mat-icon>
74+
</button>
75+
```
76+
77+
If you are using a custom icon element that is not a `mat-icon` or `.material-icons`, add the
78+
`matButtonIcon` attribute so that the button can project it into the correct slot:
79+
80+
```html
81+
<button matButton>
82+
<my-custom-icon matButtonIcon>custom</my-custom-icon>
83+
Action
84+
</button>
85+
```
86+
4687
### Interactive disabled buttons
4788
Native disabled `<button>` elements cannot receive focus and do not dispatch any events. This can
4889
be problematic in some cases because it can prevent the app from telling the user why the button is

0 commit comments

Comments
 (0)