CredentialButton
A credential action button that opens a password or secret update flow in a controlled popper.
import { CredentialButton } from "@schukai/monster/source/components/form/credential-button.mjs";Introduction
The Monster CredentialButton opens a focused credential update flow from a single trigger. Use it for password changes, secret rotation or similar account-security tasks that should stay compact and contextual.
When to use CredentialButton
- Use it for password and secret changes: The component keeps the flow behind one deliberate action.
- Use it when the edit surface should stay temporary: A popper avoids navigating away from the current page.
- Do not use it for broad account settings: Larger profile forms usually deserve a dedicated page or panel.
Typical mistakes
Keep the credential flow explicit and secure. Avoid overloading the component with unrelated account preferences, and surface validation rules clearly when password complexity matters.
Credential Button Simple
This example opens the credential popper, accepts a new password, and submits it against a mocked endpoint.
Javascript
import "@schukai/monster/source/components/form/credential-button.mjs";
const button = document.getElementById("credential-button-demo");
const originalFetch = window.fetch.bind(window);
window.fetch = (input, init = {}) => {
const url = typeof input === "string" ? input : input?.url;
if (url === "/mock/credential-button") {
return Promise.resolve(
new Response(JSON.stringify({ ok: true }), {
status: 200,
headers: { "content-type": "application/json" },
}),
);
}
return originalFetch(input, init);
};
button.setOption("url", "/mock/credential-button");
button.setOption("labels.button", "Change password");
button.setOption("labels.title", "Password");
button.setOption("labels.description", "Enter a new password and submit it.");<script type="module">import "@schukai/monster/source/components/form/credential-button.mjs";
const button = document.getElementById("credential-button-demo-run");
const originalFetch = window.fetch.bind(window);
window.fetch = (input, init = {}) => {
const url = typeof input === "string" ? input : input?.url;
if (url === "/mock/credential-button") {
return Promise.resolve(
new Response(JSON.stringify({ ok: true }), {
status: 200,
headers: { "content-type": "application/json" },
}),
);
}
return originalFetch(input, init);
};
button.setOption("url", "/mock/credential-button");
button.setOption("labels.button", "Change password");
button.setOption("labels.title", "Password");
button.setOption("labels.description", "Enter a new password and submit it.");</script>HTML
<monster-credential-button id="credential-button-demo">
Change password
</monster-credential-button>Stylesheet
/** no additional stylesheet is defined **/Credential Button Retry
This example demonstrates the failure and retry flow of monster-credential-button with a mocked endpoint.
Javascript
import "@schukai/monster/source/components/form/credential-button.mjs";
const button = document.getElementById("credential-button-retry-demo");
const status = document.getElementById("credential-button-retry-status");
const originalFetch = window.fetch.bind(window);
let attempts = 0;
window.fetch = (input, init = {}) => {
const url = typeof input === "string" ? input : input?.url;
if (url === "/mock/credential-button-retry") {
attempts += 1;
status.textContent = "Submit attempt " + attempts;
if (attempts === 1) {
return Promise.resolve(
new Response(JSON.stringify({ message: "Temporary policy check failed." }), {
status: 400,
headers: { "content-type": "application/json" },
}),
);
}
return Promise.resolve(
new Response(JSON.stringify({ ok: true }), {
status: 200,
headers: { "content-type": "application/json" },
}),
);
}
return originalFetch(input, init);
};
button.setOption("url", "/mock/credential-button-retry");
button.setOption("labels.button", "Rotate API key");
button.setOption("labels.title", "New credential");
button.setOption("labels.description", "Submit once to see the failure state, then retry.");
button.setOption("payload.data", { scope: "deployments" });<script type="module">import "@schukai/monster/source/components/form/credential-button.mjs";
const button = document.getElementById("credential-button-retry-demo-run");
const status = document.getElementById("credential-button-retry-status-run");
const originalFetch = window.fetch.bind(window);
let attempts = 0;
window.fetch = (input, init = {}) => {
const url = typeof input === "string" ? input : input?.url;
if (url === "/mock/credential-button-retry") {
attempts += 1;
status.textContent = "Submit attempt " + attempts;
if (attempts === 1) {
return Promise.resolve(
new Response(JSON.stringify({ message: "Temporary policy check failed." }), {
status: 400,
headers: { "content-type": "application/json" },
}),
);
}
return Promise.resolve(
new Response(JSON.stringify({ ok: true }), {
status: 200,
headers: { "content-type": "application/json" },
}),
);
}
return originalFetch(input, init);
};
button.setOption("url", "/mock/credential-button-retry");
button.setOption("labels.button", "Rotate API key");
button.setOption("labels.title", "New credential");
button.setOption("labels.description", "Submit once to see the failure state, then retry.");
button.setOption("payload.data", { scope: "deployments" });</script>HTML
<div style="display:grid;gap:1rem;">
<monster-credential-button id="credential-button-retry-demo">
Rotate API key
</monster-credential-button>
<div id="credential-button-retry-status">First submit will fail, second will succeed.</div>
</div>Stylesheet
/** no additional stylesheet is defined **/Component Design
The button extends the shared form action model and adds credential-specific handling so secure actions can be requested with a focused UI element.
Styling Hooks
labels: Adjusts button text and related messaging.dataset: Connects the action to surrounding workflow data.::part(button): Styles the visible trigger.
HTML Structure
<monster-credential-button></monster-credential-button>JavaScript Initialization
const element = document.createElement('monster-credential-button');
document.body.appendChild(element);Exported
CredentialButtonDerived 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.
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]()- {CredentialButton}
Events
The component emits the following events:
monster-credential-submitmonster-credential-successfulmonster-credential-failed
For more information on how to handle events, see the mdn documentation.