Skip to content
QwryAI
Documentation
Pages

Widgets

Interactive

The component visitors click to act: Button

Button

A button that runs a function when clicked, or submits the form it sits in. Buttons are how visitors act on a Widget: track a parcel, confirm a choice, open a page or reply in the chat.

jsx
<Button label="Track package" iconStart="truck" onClickAction={{ functionName: "trackPackage" }} />

Props

PropTypeDefaultDescription
labelstring | {text, color?, weight?}—Button text.
onClickActionaction—Function to run on click.
submitbooleanfalseSubmits the Form the button is in.
variantsolid | soft | outline | ghostsolidVisual style.
colorprimary | secondary | success | danger | warning | caution | info | discovery, or any colorprimaryButton color.
size3xs | 2xs | xs | sm | md | lg | xl | 2xl | 3xllgButton height, from 22 px (3xs) to 48 px (3xl). lg is 36 px.
iconStarticon—Icon before the label. See Icon field format.
iconEndicon—Icon after the label.
iconSizexs | sm | md | lg | xl | 2xl | 3xlfollows sizeSize of both icons.
pillbooleantrueFully rounded ends. Set pill={false} for rounded corners.
blockbooleanfalseStretches the button to the full width of its container.
widthnumber | string—Fixed width.
uniformbooleanfalseMakes the button square, for an icon-only button.
disabledbooleanfalseGreys the button out and blocks clicks.
lineThroughbooleanfalseStrikes the label through.
ariaLabelstringthe labelName read by screen readers. Set it on icon-only buttons.

While its function runs, a button shows a spinner and can't be clicked again, unless loadingBehavior is "none" or "container".

Examples

Basic action button

A button that runs one function.

jsx
<Button label="Refresh status" onClickAction={{ functionName: "refreshStatus" }} />

Form submit button

With submit, the button submits its form, which runs the form's function with every field value. Use it in a Form or in a Card with asForm.

jsx
<Form onSubmitAction={{ functionName: "subscribe" }} gap={3}>
  <Label value="Email" fieldName="email" />
  <Input name="email" inputType="email" required />
  <Button label="Subscribe" submit color="success" />
</Form>

Icon buttons

Add an icon before or after the label with iconStart and iconEnd. For a square icon-only button, leave out label, set uniform and give it an ariaLabel.

jsx
<Button
  label="Download invoice"
  iconStart="download"
  variant="outline"
  color="secondary"
  onClickAction={{ functionName: "downloadInvoice" }}
/>
jsx
<Button
  iconStart="x"
  uniform
  variant="ghost"
  ariaLabel="Close"
  onClickAction={{ functionName: "close" }}
/>

Full-width button

Set block to make the button fill its container.

jsx
<Button label="Continue to checkout" block pill={false} onClickAction={{ functionName: "checkout" }} />

Button with additional inputs

Send a value along with the click. This matters for buttons drawn from a list, where each must say which item was clicked.

jsx
{items.map((item) => (
  <Button
    key={item.sku}
    label={`Return ${item.name}`}
    variant="outline"
    onClickAction={{
      functionName: "startReturn",
      additionalInputs: { sku: item.sku }
    }}
  />
))}

Next steps

Explore the documentation