CodeButton
The full front-end flow of a “get code” button: click → emit oas-send → start the cooldown countdown → become resendable. Sending the request is the host's job; the component owns interaction and state.
Basic usage
Clicking starts the cooldown immediately (60 seconds by default); while cooling down the button is disabled and shows the remaining seconds.
cooldown=10
Waiting to send…
Example
cooldown=3 (see the whole flow quickly)
Example
Controlled flow (start the cooldown after the request succeeds)
oas-send can be intercepted with preventDefault(): the cooldown does not start automatically, and the host calls start() once the request succeeds. Below simulates a request that succeeds after 800 ms.
intercept → request → start()
Not sent
Example
Loading and disabled
loading / disabled
Example
loading: shows the built-in spinner, setsaria-busy="true"and blocks repeated clicksdisabled: not clickable and no events are dispatched
Custom content (default slot)
Slot content is used for the idle state; during the countdown the built-in countdown text is still shown (so custom copy cannot hide the remaining time).
default slot
Example
Events
| Event | When | detail |
|---|---|---|
oas-send | Clicked while clickable (preventDefault skips the cooldown) | { cooldown } |
API
oas-code-button
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
cooldown | Cooldown seconds (default 60); invalid/non-positive values fall back with a warning | string | — |
disabled | Disabled: not clickable and no events are dispatched | boolean | — |
loading | Request in flight: spinner + aria-busy + blocks repeated clicks | boolean | — |
Property (JS property; see each row for attribute reflection)
| Property | Description | Type | Default |
|---|---|---|---|
counting | Whether the cooldown is running (read-only) | boolean | — |
remaining | Remaining cooldown seconds (read-only) | number | 0 |
Methods
| Method | Signature | Description |
|---|---|---|
start | start(seconds?: number): void | Start the cooldown (defaults to cooldown) |
reset | reset(): void | End the cooldown immediately and return to idle |
Events
| Event | Description |
|---|---|
oas-send | Fired on click while clickable, detail: { cooldown }; call preventDefault() to skip the automatic cooldown (host calls start() after success) |
Slots
| Name | Description |
|---|---|
| default | Custom button content (idle state; the built-in countdown text takes over during cooldown) |