NG Kit

Base Button

The Base Button is the foundation every ng-kit button is built on. It encapsulates the shared button logic, accessibility and styling — label, icon, disabled and loading state, ARIA attributes and keyboard interactions — that all other buttons inherit. It is not meant to be used on its own; use one of the specific buttons below, or extend it to build your own.

Usage

Use the button through its directive selector on any element, or through its component selector. The directive form is preferred for new code; the component form remains supported.

html
<!-- The base supplies icon / label / loading to every button. Shown here
     via <primary-button>, which extends BaseButtonDirective. -->
<primary-button [loading]="loading()" [showIcon]="true" icon="save" label="Save"></primary-button>
<button ariaLabel="Submit" [loading]="loading()" primaryButton mat-raised-button>Submit</button>

API

The shared base every ng-kit button extends. It defines the common inputs and outputs that all other buttons inherit; consume it through one of the specific buttons rather than directly.

Inputs

NameTypeDefaultDescription
loadingbooleanfalseShows a spinner and the loading label, and disables the button.
disabledbooleanfalseDisables the button.
type'button' | 'submit''button'Native button type attribute.
loadingLabelstring'Saving...'Text shown while loading is true.
labelstring'Save'Button label text.
iconstring'save'Material icon name rendered before the label.
showIconbooleantrueWhether the leading icon is rendered.
styleobject | nullInline style object applied to the button.
classesstring'btn'CSS classes applied to the button.
dataCystring'save-button'data-cy attribute for e2e selectors.

Outputs

NamePayloadDescription
onClickMouseEventEmitted when the button is clicked.
onFocusFocusEventEmitted when the button gains focus.
onBlurFocusEventEmitted when the button loses focus.
onKeyDownKeyboardEventEmitted on key down while focused.
onKeyUpKeyboardEventEmitted on key up while focused.