Button
Starts an action. Five kinds tell the user how much weight the action carries.
When to use
- One primary button per screen area: the action most people came for.
- Accent only for a single, decisive action such as Approve.
- Ghost for icon buttons and tools that repeat in every row.
When not to use
- An irreversible action: use HoldButton or Confirm.
- Switching between views: use Segmented or Tabs.
Examples
Kinds
Loading the example
<k:Stack row="true" gap="10">
<k:Button kind="primary" text="Save" press=".onPress"/>
<k:Button kind="accent" text="Approve" icon="check" press=".onPress"/>
<k:Button text="Duplicate" press=".onPress"/>
<k:Button kind="ghost" icon="palette" label="Appearance" press=".onPress"/>
<k:Button kind="danger" text="Reject" press=".onPress"/>
</k:Stack>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Toast"], (Controller, Toast) => Controller.extend("sample.Buttons", {
onPress(event) {
const button = event.getSource();
Toast.show("Pressed: " + (button.getText() || button.getLabel()));
}
}));Menu
Add menuItems and the button opens a menu. menuSelect carries the key of the chosen row.
Loading the example
<k:Button text="Export" menuSelect=".onMenu">
<k:MenuItem key="xlsx" text="Excel"/>
<k:MenuItem key="csv" text="CSV"/>
</k:Button>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Toast"], (Controller, Toast) => Controller.extend("sample.Menu", {
onMenu(event) {
Toast.show(event.getParameter("key"));
}
}));Loading and disabled
loading blocks further presses until you set it back to false.
Loading the example
<k:Stack row="true" gap="10">
<k:Button kind="primary" text="Post invoice" loading="{/busy}" press=".onPost"/>
<k:Button text="Not available" enabled="false"/>
</k:Stack>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Toast"], (Controller, Toast) => Controller.extend("sample.Loading", {
onPost() {
const model = this.getView().getModel();
model.setProperty("/busy", true);
setTimeout(() => {
model.setProperty("/busy", false);
Toast.show("Invoice posted");
}, 1500);
}
}));Keyboard
- Enter Space
- Press, or open the menu
- ↓
- Open the menu
- Esc
- Close the menu
API
Properties
| Name | Type | Default | Description |
|---|---|---|---|
text | string | Button text | |
icon | string | Icon name | |
kind | string | neutral | primary, accent, neutral, ghost or danger |
hint | string | Displayed keyboard shortcut | |
label | string | Accessible name and tooltip for an icon-only button | |
loading | boolean | false | Whether an operation is in progress |
enabled | boolean | true | Whether the button can be used |
wide | boolean | false | Whether the button fills its container |
Aggregations
| Name | Type | Description |
|---|---|---|
menuItems | MenuItem[] | Menu entries |
Events
| Name | Type | Description |
|---|---|---|
press | The button was pressed | |
menuSelect | key: string | A menu entry was selected |
MenuItem
An entry in a button's menu.
Properties
| Name | Type | Default | Description |
|---|---|---|---|
key | string | Entry key | |
text | string | Menu text | |
icon | string | Icon name | |
danger | boolean | false | Whether the action is hard to reverse |