Search

2nd Level w/Tabs

Example

Usage Examples

Code Example

A button object should always use a <button> element. Also make sure to add type="button" or some browsers will treat this as a submit button and refresh the page.

There are five types of buttons, all controlled by classes and markup.

  • btn-primary – Primary action form button
  • btn-secondary – Secondary action form button
  • btn-tertiary or btn – Normal tertiary button
  • btn-icon – Icon only button
  • btn-menu – A button with a context menu attached

All buttons are assumed to include an icon and a text label. An icon can be added by including the SVG icon element and use a span to hold the button text.

<button class="btn-primary" type="button" id="page-button-primary">Action</button>

<button class="btn-secondary" type="button" id="page-button-secondary">Action</button>

<button type="button" class="btn-tertiary" id="page-button-tertiary">
  <svg role="presentation" aria-hidden="true" focusable="false" class="icon">
    <use href="#icon-filter"></use>
  </svg>
  <span>Action</span>
</button>

<button type="button" class="btn-icon" disabled id="page-button-icon">
  <span>Date</span>
  <svg role="presentation" aria-hidden="true" focusable="false" class="icon">
    <use href="#icon-calendar"></use>
  </svg>
</button>

You can also use the button component to make a toggle button. Here is an example of a favorite style icon you can toggle on and off. Adding the class icon-favorite will change the icon color to a gold color instead of the usually azure toggle buttons when on.

<button type="button" id="favorite" class="btn-icon icon-toggle" title="Favorite">
   <svg class="icon-test icon" focusable="false" aria-hidden="true" role="presentation">
    <use href="#icon-star-filled"></use>
   </svg>
   <span>Favorite</span>
</button>

If you need a menu button, note that it is comprised of the popupmenu and the button component.

Once the proper markup is in place calling $(elem).button() will correctly initialize a menu button. If the arrow icon is missing in the markup it will be added. For example:

<button class="btn-menu">
  <span>Menu Button</span>
  <svg role="presentation" aria-hidden="true" focusable="false" class="icon icon-dropdown">
    <use href="#icon-dropdown"></use>
  </svg>
</button>
<ul class="popupmenu">
  <li><a href="#" id="menu-option-1">Menu Option #1</a></li>
  <li><a href="#" id="menu-option-2">Menu Option #2</a></li>
  <li><a href="#" id="menu-option-3">Menu Option #3</a></li>
</ul>

We introduce a new style button in generative AI purpose. This example button is an generative AI button specifically crafted for triggering the generation of AI insights.

Here's the example markup:

<!-- Primary -->
<button class="btn-primary btn-generative" type="button" id="btn-generate-ai-1">
  <span>Generate</span>
  <svg role="presentation" aria-hidden="true" focusable="false" class="icon">
    <use href="#icon-genai"></use>
  </svg>
</button>

<!-- Tertiary -->
<button class="btn-tertiary btn-generative" type="button" id="btn-tertiary-generate-ai-1">
  <span>Generate</span>
</button>

<!--Generative Button Icon -->
<button type="button" class="btn-icon btn-generative" id="gen-icon-ai-1">
  <span>Date</span>
  <svg role="presentation" aria-hidden="true" focusable="false" class="icon">
    <use href="#icon-genai"></use>
  </svg>
</button>

We created an API called performGenerativeAction() by replacing the content of a button with a loading indicator, then replacing it with generated AI content after a specified delay.

$('#btn-tertiary-generate-ai-1').on('click keypress', function (e) {
  e.preventDefault();
  var $btn = $(this);
  var btnApi = $btn.data('button');
  btnApi.performGenerativeAction(10000);
});

Implementation Tips

  • Make sure to add an automation-id or permanently unique id for testing that remains the same across versions.
  • Do not use any elements other than button attributes for buttons.
  • Press State has a touch effect which requires JS to implement
  • Buttons can optionally have tooltips via adding a title attribute

Accessibility

  • Make sure form buttons have a succinctly descriptive value that indicates its purpose

Testability

In most cases, special attributes or automation ids should be added directly to the button markup:

<button id="my-button" data-automation-id="my-button" class="btn-primary">
  <span>My Button</span>
</button>

It's also possible to use the Javascript IDS Button API to add attributes programmatically. This is helpful when composing more complex components using the button as a trigger:

$('#my-button').button({
  attributes: [
    {
      name: 'data-automation-id',
      value: 'my-button'
    }
  ]
})

Keyboard Shortcuts

  • Spacebar or Enter keys execute the action for that button. If the button activation closes the containing entity or launches another entity, then focus moves to the newly-opened entity. If the button activation does not close or dismiss the containing entity, then focus remains on the button. An example might be an "Apply" or "Recalculate" button.
  • Enter If the button is a menu button the enter key will toggle the menu. Use the arrow keys and enter to select in the menu. See popupmenu for details on using the keyboard in the the open menu.

Responsive Guidelines

  • Buttons can optionally be 100% width of their parent container on mobile breakpoints

Upgrading from 3.X

  • Change class inforFormButton default to btn-primary
  • Change class inforFormButton to btn-secondary

Workaround for title to display as tooltip on disabled buttons

  • Disabled elements do not handle events in most browsers. This necessitates the need for an alternate element to handle the Tooltip.plugin which adds functionality that strips the title and renders it as a tooltip on the hover event of the element.
  • Include <div title="{{desired title/tooltip}}}">{{button content}}</div> as child of <button disabled></button> to allow hover event to engage tooltip functionality, taking title from inner div and displaying as tooltip.

button

IDS Button Component

new Button(element: string, settings: string?)

Parameters
Name Type Description
element string The component element.
settings string? The component settings.
settings.toggleOnIcon string=null The icon to use for on state on toggle buttons
settings.toggleOffIcon string=null The icon to use for off state on toggle buttons
settings.replaceText string=false If true the selection will be used to replace the content
settings.hideMenuArrow string=false If true and the button is a menu button, the popup arrow will be hidden.
settings.hitbox boolean=false If true, it will add an invisible and clickable area around the button

Instance Members

tooltipAPI

tooltipAPI

Returns Tooltip: component instance, if applicable
icon

icon

Returns HTMLElement: a reference to this button’s icon element
disabled

disabled

Returns boolean: whether or not this component is currently disabled
disabled

disabled

Parameters
Name Type Description
val boolean the value
Returns void:
init()

Initializes the Button Component

init(): void

Returns void:
createNotificationBadge()

Builds notification badge for button

createNotificationBadge(): void

Returns void:
createRipple(e?)

createRipple(e: jQuery.Event?): void

Parameters
Name Type Description
e jQuery.Event? incoming event object used for positioning. If not provided, the coordinates for the placement of the ripple will be at the center of the element.
Returns void:
render()

Renders the contents of the button

render(): void

Returns void:
renderAttributes()

Handle attributes from settings, if applicable

renderAttributes(): void

Returns void:
getSettingsFromElement(dontStoreSettings)

Backwards compatability method for buttons that were previously defined by markup. This will take an existing DOM element representing a button, and rectify internal settings to match the element’s state. NOTE: When actually storing settings, the lifecycle of the Button component is specifically designed for this method to run ONE time, at the beginning of its creation. It should not run every time updated() occurs. To detect current settings without overwriting them, use a true dontStoreSettings argument.

getSettingsFromElement(dontStoreSettings: boolean): object

Parameters
Name Type Description
dontStoreSettings boolean= false if true, will not store the current settings internally while running.
Returns object: containing a JSON-friendly representation of this element’s current state
performAnimation(delay)

Performs a generative action by replacing the content of a button with a loading indicator, then replacing it with generated AI content after a specified delay.

performAnimation(delay: number): void

Parameters
Name Type Description
delay number= 0 The delay (in milliseconds) before replacing the loading indicator.
Returns void:
startAnimation()

Starts a generative action.

startAnimation(): void

Returns void:
stopAnimation()

Stops a generative action.

stopAnimation(): void

Returns void:
renderGenerativeStyles()

Renders a generative action by replacing the content of a button with a loading indicator.

renderGenerativeStyles(): void

Returns void:
removeGenerativeStyles()

Removes a generative action by replacing it with generated AI content.

removeGenerativeStyles(): void

Returns void:
toData(addContextElement)

Provides a JSON-compatible data representation of this button component for use with higher-level components.

toData(addContextElement: boolean): object

Parameters
Name Type Description
addContextElement boolean if true, adds a reference to this button element to the return data (NOT JSON-compatible).
Returns object: JSON-compatible representation of this button’s configuration.
pressed

pressed

Returns boolean: whether or not this is a valid toggle button in a pressed state.
pressed

On a Toggle or Favorite button, sets the current pressed state.

pressed

Parameters
Name Type Description
val boolean whether or not to set a “pressed” state on this valid toggle button.
Returns void:
toggle()

Toggles the current state of an icon button.

toggle(): void

Returns void:
updated(settings)

Update the component with new settings.

updated(settings: object): Button

Parameters
Name Type Description
settings object The settings you would like to modify.
Returns Button: This component’s API.
destroy()

Teardown and remove any added markup and events.

destroy(): void

Returns void:

Events

click

Fires when the button is clicked (if enabled).

click

Parameters
Name Type Description
event object The jquery event object
focus

Fires when the button is focused.

focus

Parameters
Name Type Description
event object The jquery event object

elem

The element representing the button.

$elem

Type: jQuery

elem

The element representing the button.

$elem

Type: jQuery

svg

The SVG element within the button.

$svg

Type: jQuery