NcActionButton
Button component to be used in Actions
Props
Prop name | Description | Type | Values | Default |
---|---|---|---|---|
icon | Icon to show with the action, can be either a CSS class or an URL | string | - | '' |
title | Title to show next to the icon | string | - | '' |
closeAfterClick | Whether we close the Actions menu after the click | boolean | - | false |
ariaLabel | Aria label for the button. Not needed if the button has text. | string | - | '' |
disabled | disabled state of the action button | boolean | - | false |
Events
Event name | Properties | Description |
---|---|---|
click | Emitted when the action is clicked |
Slots
Name | Description | Bindings |
---|---|---|
icon | Manually provide icon | |
default |
This component is made to be used inside of the NcActions component slots.
vue
<template>
<div style="display: flex; align-items: center;">
<NcActions>
<NcActionButton @click="showMessage('Delete')">
<template #icon>
<Delete :size="20" />
</template>
Delete
</NcActionButton>
<NcActionButton
:close-after-click="true"
@click="showMessage('Delete and close menu')"
>
<template #icon>
<Delete :size="20" />
</template>
Delete and close
</NcActionButton>
<NcActionButton :close-after-click="true" @click="focusInput">
<template #icon>
<Plus :size="20" />
</template>
Create
</NcActionButton>
<NcActionButton :disabled="true" @click="showMessage('Disabled')">
<template #icon>
<Delete :size="20" />
</template>
Disabled button
</NcActionButton>
</NcActions>
<input ref="input" />
</div>
</template>
<script>
import Delete from "vue-material-design-icons/Delete";
import Plus from "vue-material-design-icons/Plus";
export default {
components: {
Delete,
Plus
},
methods: {
showMessage(msg) {
alert(msg);
},
focusInput() {
this.$nextTick(() => this.$refs.input.focus());
}
}
};
</script>
If you're using a long text you can specify a title
vue
<template>
<NcActions>
<NcActionButton icon="icon-add" @click="showMessage('Add')">
Add new
</NcActionButton>
<NcActionButton title="Long button" @click="showMessage('Delete')">
<template #icon>
<Delete :size="20" />
</template>
This button is associated with a very long text.\nAnd with new lines too.
</NcActionButton>
</NcActions>
</template>
<script>
import Delete from "vue-material-design-icons/Delete";
export default {
components: {
Delete
},
methods: {
showMessage(msg) {
alert(msg);
}
}
};
</script>
Action icon attribute with a single action
vue
<template>
<NcActions>
<NcActionButton icon="icon-add" @click="showMessage('Add')">
Add new
</NcActionButton>
</NcActions>
</template>
<script>
export default {
methods: {
showMessage(msg) {
alert(msg);
}
}
};
</script>
You can also use a custom icon, for example from the vue-material-design-icons library:
vue
<template>
<NcActions>
<NcActionButton>
<template #icon>
<HandBackLeft :size="20" />
</template>
Raise left hand
</NcActionButton>
<NcActionButton>
<template #icon>
<HandBackRight :size="20" />
</template>
Raise right hand
</NcActionButton>
</NcActions>
</template>
<script>
import HandBackLeft from "vue-material-design-icons/HandBackLeft";
import HandBackRight from "vue-material-design-icons/HandBackRight";
export default {
components: {
HandBackLeft,
HandBackRight
}
};
</script>