|
1 | | -# md-button-toggle |
2 | | - |
3 | | -`MdButtonToggle` is a group of buttons that can be toggled. |
4 | | -There are two modes, `multiple` and `exclusive`. |
5 | | -When in 'exclusive' mode, only one button can be selected at a time (like radio buttons). |
6 | | -When in 'multiple' mode, multiple buttons can be selected at once (like checkboxes). |
7 | | -You can read more about button toggles in the |
8 | | -[Material Design spec](https://material.google.com/components/buttons.html#buttons-toggle-buttons). |
9 | | - |
10 | | -## Usage |
11 | | - |
12 | | -### Basic Usage |
13 | | - |
14 | | -`md-button-toggle` can be used on its own and acts as a checkbox. |
15 | | - |
16 | | -```html |
17 | | -<md-button-toggle>Bold</md-button-toggle> |
18 | | -``` |
19 | | - |
20 | | -Output: |
21 | | - |
22 | | - |
23 | | - |
24 | | -### Exclusive Selection |
25 | | - |
26 | | -`md-button-toggle` can be used in an exclusive selection group when surrounded by |
27 | | -`md-button-toggle-group`. This styles all buttons within the group to appear as a single |
28 | | -group of button toggles and allows only one button toggle to be selected at a time. |
29 | | - |
30 | | -```html |
31 | | -<md-button-toggle-group name="alignment"> |
32 | | - <md-button-toggle value="left"><md-icon>format_align_left</md-icon></md-button-toggle> |
33 | | - <md-button-toggle value="center"><md-icon>format_align_center</md-icon></md-button-toggle> |
34 | | - <md-button-toggle value="right"><md-icon>format_align_right</md-icon></md-button-toggle> |
35 | | - <md-button-toggle value="justify"><md-icon>format_align_justify</md-icon></md-button-toggle> |
36 | | -</md-button-toggle-group> |
37 | | -``` |
38 | | - |
39 | | -Output: |
40 | | - |
41 | | - |
42 | | - |
43 | | -### Multiple Selection |
44 | | - |
45 | | -`md-button-toggle` can be used in a multiple selection group when surrounded by |
46 | | -`md-button-toggle-group multiple`. This styles all buttons within the group to appear as a single |
47 | | -group of button toggles. This component does not yet support `NgModel` when using `multiple` mode. |
48 | | - |
49 | | -```html |
50 | | -<md-button-toggle-group multiple> |
51 | | - <md-button-toggle>Flour</md-button-toggle> |
52 | | - <md-button-toggle>Eggs</md-button-toggle> |
53 | | - <md-button-toggle>Sugar</md-button-toggle> |
54 | | - <md-button-toggle>Milk</md-button-toggle> |
55 | | -</md-button-toggle-group> |
56 | | -``` |
57 | | - |
58 | | -Output: |
59 | | - |
60 | | - |
61 | | - |
62 | | -## Dynamic Exclusive Selection |
63 | | - |
64 | | -`md-button-toggle`s can be used with `ngModel` to dynamically create groups and update the value for |
65 | | -a group. |
66 | | - |
67 | | -```html |
68 | | -<md-button-toggle-group name="pies" [(ngModel)]="favoritePie"> |
69 | | - <md-button-toggle *ngFor="let pie of pieOptions" [value]="pie"> |
70 | | - {{pie}} |
71 | | - </md-button-toggle> |
72 | | -</md-button-toggle-group> |
73 | | -<p>Your favorite type of pie is: {{favoritePie}}</p> |
74 | | -``` |
75 | | - |
76 | | -### Disabled Button Toggle |
77 | | - |
78 | | -`md-button-toggle-group` and `md-button-toggle` can both be disabled by adding a `disabled` |
79 | | -attribute to either one. Adding `disabled` to an exclusive group or a multiple group will disable |
80 | | -the entire group. Adding `disabled` to a single toggle will disable that toggle. |
81 | | - |
82 | | -```html |
83 | | -<md-button-toggle-group disabled> |
84 | | - <md-button-toggle value="one">One</md-button-toggle> |
85 | | - <md-button-toggle value="two">Two</md-button-toggle> |
86 | | - <md-button-toggle value="three">Three</md-button-toggle> |
87 | | -</md-button-toggle-group> |
88 | | - |
89 | | -<md-button-toggle-group> |
90 | | - <md-button-toggle value="red" disabled>Red</md-button-toggle> |
91 | | - <md-button-toggle value="blue">Blue</md-button-toggle> |
92 | | -</md-button-toggle-group> |
93 | | -``` |
94 | | - |
95 | | -Output: |
96 | | - |
97 | | - |
98 | | - |
99 | | -## `<md-button-toggle>` |
100 | | - |
101 | | -### Bound Properties |
102 | | - |
103 | | -| Name | Type | Description | |
104 | | -| --- | --- | --- | |
105 | | -| `id` | string | The unique ID of the toggle. IDs are generated by default when not specified. | |
106 | | -| `name` | string | Optional, defaults to parent group name if one exists for exclusive selection toggles, otherwise null. This is used to differentiate between different groups. | |
107 | | -| `value` | any | Value of the toggle. Only used when in a group to determine which are selected. | |
108 | | -| `checked` | boolean | Optional, default = `false`. Whether or not the toggle is checked. | |
109 | | -| `disabled` | boolean | Optional, default = `false`. Whether or not the toggle is disabled | |
110 | | - |
111 | | -### Events |
112 | | - |
113 | | -| Name | Description | |
114 | | -| --- | --- | |
115 | | -| `change` | Emitted when the `checked` value is changed. | |
116 | | - |
117 | | -## `<md-button-toggle-group>` |
118 | | - |
119 | | -### Bound Properties |
120 | | - |
121 | | -| Name | Type | Description | |
122 | | -| --- | --- | --- | |
123 | | -| `name` | string | Optional, the name of the group. | |
124 | | -| `disabled` | boolean | Optional, default = `false`. | |
125 | | -| `value` | any | The current value for the group. Will be set to the value of the selected toggle or a list of values from the selected toggles. | |
126 | | -| `selected` | `mdButtonToggle` | The current selected toggle or a list of the selected toggles. | |
127 | | -| `vertical` | boolean | Whether the group should show the toggles vertically. Default is `false`. | |
128 | | - |
129 | | -### Attributes |
130 | | - |
131 | | -| Name | Type | Description | |
132 | | -| --- | --- | --- | |
133 | | -| `multiple` | boolean | Optional, default = `false`. Whether or not the group allows multiple selection. | |
134 | | - |
135 | | -### Events |
136 | | - |
137 | | -| Name | Description | |
138 | | -| --- | --- | |
139 | | -| `change` | Emitted when the `value` of the group changes. | |
| 1 | +Please see the official documentation at https://material.angular.io/components/component/button-toggle |
0 commit comments