OGE logoOGE

Button Interactions

Four interaction guards you would otherwise hand-roll on every project: promise-aware action with automatic loading and single-flight protection, clickGuard throttle/debounce, holdToConfirm for destructive actions and autoRepeat for spinner buttons. All of them funnel into the (clicked) output.

action loading clickGuard holdToConfirm autoRepeat

Async actions & loading

Bind a promise-returning function to action and the button manages the async lifecycle for you: it flips loading on, disables itself, silently ignores further clicks until the promise settles (single-flight), then emits actionDone with the resolved value or actionFailed with the error. No flags to manage in your component.

[action] → auto loading single-flight (actionDone)
saved ×0 · failed ×0 — spam the buttons: while pending, extra clicks are ignored.

Click guard

Rate-limits the clicked output against double submissions and spam. true is a ready-made 500ms throttle (first click wins, the window swallows the rest); { mode: 'debounce', ms } waits for the clicks to stop and fires once. The guard also applies to hold completions and auto-repeat ticks.

clickGuard: true = throttle 500ms debounce trailing
throttled ×0 · debounced ×0

Hold to confirm

Arms destructive actions behind an uninterrupted press: a fill sweeps across the button while held and brightens when the duration elapses — releasing then fires clicked. Quick taps do nothing. Escape, dragging away or pointer-cancel aborts; keyboard users hold Space or Enter. The fill is pure CSS (transform-only), so it costs no script time.

holdToConfirm Escape cancels keyboard: hold Space
confirmed ×0 — quick taps do nothing; hold until the bar fills, then release.

Auto-repeat

For spinner and counter buttons: holding the button re-fires clicked — once immediately, then repeatedly after delayMs at intervalMs. Repeating stops on release, on pointer-cancel, or the moment the button becomes disabled. Mutually exclusive with holdToConfirm (hold wins).

autoRepeat delay + interval spinner pattern
0hold either button down

Notes

  • loading is a two-way model — drive it manually or let action manage it. A loading button is disabled and exposes aria-busy plus a screen-reader label from the messages config (provideOgeButtonsConfig).
  • Guards compose: a hold completion or auto-repeat tick still passes through clickGuard before emitting.
  • holdToConfirm and autoRepeat are mutually exclusive; hold wins and dev mode logs an error.
  • In gesture modes native clicks are swallowed (and stopped from bubbling) so a quick tap can never trigger outer (click) listeners.