ActionButton
A button that opens a popper with contextual actions such as edit, duplicate or archive.
import { ActionButton } from "@schukai/monster/source/components/form/action-button.mjs";Introduction
The Monster ActionButton is a compact entry point for a small set of contextual commands. Use it when one trigger should open related actions such as edit, duplicate, archive or export without taking permanent space in the UI.
When to use ActionButton
- Use it for grouped actions: Keep secondary commands behind one clear trigger.
- Use it in toolbars and row actions: The component works well where space is limited.
- Do not use it for a single primary action: A normal button is clearer when there is only one obvious outcome.
Typical mistakes
Keep the command list short. If the popper becomes a long menu or needs rich filtering, another navigation pattern is usually easier to scan and easier to operate.
Inline Menu
This example demonstrates how to create an Action Button component.
Javascript
import '@schukai/monster/source/components/form/action-button.mjs';
const element = document.querySelector('monster-action-button');
element.setOption("buttons" , [
{
label: "Button 1",
class: "monster-button-primary-1",
action: () => {
console.log("Button 1 clicked");
}
},
{
label: "Button 2",
class: "monster-button-primary-2",
action: () => {
console.log("Button 2 clicked");
}
}
])<script type="module">import '@schukai/monster/source/components/form/action-button.mjs';
const element = document.getElementById('Agh3a')
element.setOption("buttons" , [
{
label: "Button 1",
class: "monster-button-primary-1",
action: () => {
console.log("Button 1 clicked");
}
},
{
label: "Button 2",
class: "monster-button-primary-2",
action: () => {
console.log("Button 2 clicked");
}
}
])</script>HTML
<monster-action-button>
click me!
</monster-action-button>Stylesheet
/** no additional stylesheet is defined **/Bulk Action Menu
This example uses monster-action-button as a compact bulk action menu with three distinct outcomes.
Javascript
import "@schukai/monster/source/components/form/action-button.mjs";
const element = document.getElementById("action-button-bulk-actions-demo");
const status = document.getElementById("action-button-bulk-actions-status");
element.setOption("buttons", [
{
label: "Archive selected",
class: "monster-button-outline-primary",
action: () => {
status.textContent = "Archived the selected entries.";
},
},
{
label: "Assign reviewer",
class: "monster-button-outline-secondary",
action: () => {
status.textContent = "Opened the reviewer assignment flow.";
},
},
{
label: "Export CSV",
class: "monster-button-outline-tertiary",
action: () => {
status.textContent = "Started the CSV export.";
},
},
]);<script type="module">import "@schukai/monster/source/components/form/action-button.mjs";
const element = document.getElementById("action-button-bulk-actions-demo-run");
const status = document.getElementById("action-button-bulk-actions-status-run");
element.setOption("buttons", [
{
label: "Archive selected",
class: "monster-button-outline-primary",
action: () => {
status.textContent = "Archived the selected entries.";
},
},
{
label: "Assign reviewer",
class: "monster-button-outline-secondary",
action: () => {
status.textContent = "Opened the reviewer assignment flow.";
},
},
{
label: "Export CSV",
class: "monster-button-outline-tertiary",
action: () => {
status.textContent = "Started the CSV export.";
},
},
]);</script>HTML
<div style="display:grid;gap:1rem;">
<monster-action-button id="action-button-bulk-actions-demo">
Bulk actions
</monster-action-button>
<div id="action-button-bulk-actions-status">No action selected yet.</div>
</div>Stylesheet
/** no additional stylesheet is defined **/Component Design
The ActionButton component is built using the Shadow DOM to encapsulate its structure and styling. By utilizing a shadow root, the component ensures its internal elements and styles remain protected from unintended interference caused by external CSS or JavaScript.
Shadow DOM and Accessibility
The Shadow DOM encapsulates the component's internal structure, preventing direct access to its elements. This ensures a consistent and predictable design. The component is designed with accessibility in mind, supporting semantic structure and keyboard navigation to provide an inclusive user experience.
Customizing Through Exported Parts
Specific internal elements of the ActionButton component are made available for external styling through exported parts. These parts allow developers to apply custom styles to specific sections of the component while maintaining its encapsulation.
Available Part Attributes
control: Represents the main container for the button and its popper content.button: Represents the main button element that triggers the actions.popper: Represents the dropdown area where additional action buttons are displayed.content: Represents the container for the content inside the popper.buttons: Represents the group of action buttons displayed inside the popper.
Below is an example of how to use CSS part attributes to customize the ActionButton component:
monster-action-button::part(control) {
background-color: #f0f0f0;
border: 1px solid #d0d0d0;
border-radius: 4px;
padding: 5px;
}
monster-action-button::part(button) {
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
padding: 6px 12px;
font-size: 14px;
cursor: pointer;
}
monster-action-button::part(popper) {
background-color: #ffffff;
border: 1px solid #ddd;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 4px;
padding: 10px;
}
monster-action-button::part(buttons) {
display: flex;
flex-direction: column;
gap: 5px;
}
Explanation of the Example
monster-action-button::part(control): Styles the main container with padding, a border, and background color.monster-action-button::part(button): Customizes the trigger button with a background color, padding, and rounded corners.monster-action-button::part(popper): Adds styling to the dropdown container, including a border and shadow for visibility.monster-action-button::part(buttons): Ensures the action buttons inside the dropdown are displayed in a vertical layout with spacing.
Accessibility
The ActionButton component follows accessibility best practices, ensuring support for keyboard navigation and screen readers. Users can interact with the popper actions using standard navigation methods, making the component inclusive for all users.
HTML Structure
<monster-action-button></monster-action-button>JavaScript Initialization
const element = document.createElement('monster-action-button');
document.body.appendChild(element);Exported
ActionButtonDerived from
PopperButtonOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the PopperButton.
- since
- deprecated
Properties and Attributes
The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the PopperButton.
data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.data-monster-option-[name]: Sets the value of the configuration option[name]for the collapse component when used as an HTML attribute.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the PopperButton.
Behavioral methods
showDialog()- {ActionButton}
monster-action-button-show-dialog
Static methods
[instanceSymbol]()- {symbol}
instanceof operator.getCSSStyleSheet()- {CSSStyleSheet[]}
getTag()- {string}
Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
[assembleMethodSymbol]()- {ActionButton}
Events
The component emits the following events:
monster-action-button-show-dialog
For more information on how to handle events, see the mdn documentation.