Button

Buttons are used for interface actions. Primary style should be used only once per section for main call-to-action, while other styles can appear more frequently.

Default Primary Secondary Ghost
Primary Destructive Secondary Destructive Ghost Destructive
Small Medium Large
Primary Primary Delete Delete Next
Stretch

Use the disabled attribute to disable the button.

Default Primary Secondary Ghost
Primary Destructive Secondary Destructive Ghost Destructive

Use the default state of the button along with the caret attribute to add a dropdown indicator when a button will trigger a dropdown, menu, or popover. You can see a fully functional dropdown component here .

Button

Event handlers for clicks and other user actions can be registered as you would on a standard button element (or the React equivalent ).

Default
import '@ods/components/web.button';

Note: You only need to import a web component once in your code, as it registers itself globally when defined, allowing you to use it anywhere within your application without needing to re-import it each time you want to use the component.

Slots

NameDescription
(default)The button's label.
prefixA presentational prefix icon or similar element.
suffixA presentational suffix icon or similar element.

Properties

Please note, both DOM properties and HTML attributes are shown in the table below. Unless otherwise specified, the property and attribute names are identical.

Property/AttributeReflectsTypeDefault
title
string''
variant
'default' | 'primary' | 'secondary' | 'ghost' | 'primary-destructive' | 'secondary-destructive' | 'ghost-destructive' | 'application-bar''default'
size
'small' | 'medium' | 'large''medium'
caret
booleanfalse
stretch
true | falsefalse
disabled
booleanfalse
type
'button' | 'submit' | 'reset''button'
name
string''
value
string''
href
string''
target
'_blank' | '_parent' | '_self' | '_top'
rel
string'noreferrer noopener'
download
string | undefined
form
string
formAction
formaction
string
formEnctype
formenctype
'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain'
formMethod
formmethod
'post' | 'get'
formNoValidate
formnovalidate
boolean
formTarget
formtarget
'_self' | '_blank' | '_parent' | '_top' | string
validity
validationMessage

Events

React EventDescriptionEvent Detail
ods-blurEmitted when the button loses focus.--
ods-focusEmitted when the button gains focus.--
ods-invalidEmitted when the form control has been checked for validity and its constraints aren't satisfied.--

Methods

NameDescriptionArguments
click()Simulates a click on the button.--
focus()Sets focus on the button.--
blur()Removes focus from the button.--
checkValidity()Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid.--
getForm()Gets the associated form, if one exists.--
reportValidity()Checks for validity and shows the browser's validation message if the control is invalid.--
setCustomValidity()Sets a custom validation message. Pass an empty string to restore validity.--

Parts

NameDescription
baseThe component's base wrapper.
prefixThe container that wraps the prefix.
labelThe button's label.
suffixThe container that wraps the suffix.
caretThe button's caret icon, an `<ods-icon>` element.

Dependencies

This component automatically imports the following dependencies.

  • ods-icon
The anatomy of a button component

To ensure buttons are visually accessible, any button text must pass 4.5:1 and icons must pass 3:1 contrast against their background in all interactive states. As long as text and icons within buttons meet the contrast requirement, there’s no contrast requirement for the button stroke.

Disabled buttons aren’t interactive and don’t need to pass color contrast.

Search