# Global actions

Use global actions when there's a single set of actions, or bulk actions, to be taken against any or all resources in a given view or page.

## Key UX concepts

Global actions are performed on one or multiple resources. For example, upon selection of an item in a table, at page level in a detail view page, or the selection of multiple resources, such as upon bulk selection of several items in a table.

### Page header with actions

# Page title

Actions
Create duplicate Create resource
```page-header-actions.jsx
import React from 'react';
import Header from '@cloudscape-design/components/header';
import SpaceBetween from '@cloudscape-design/components/space-between';
import ButtonDropdown from '@cloudscape-design/components/button-dropdown';
import Button from '@cloudscape-design/components/button';

const PageHeaderActions = () => (
  <Header
    variant="h1"
    actions={
      <SpaceBetween direction="horizontal" size="xs">
        <ButtonDropdown items={[{ id: 'deactivate', text: 'Deactivate' }]}>Actions</ButtonDropdown>
        <Button>Create duplicate</Button>
        <Button variant="primary">Create resource</Button>
      </SpaceBetween>
    }
  >
    Page title
  </Header>
);
export default PageHeaderActions;
```

### Card header with actions

## Cards title (1/2)

Actions
Create duplicate Create resource
1. Item 1   Description   This is the first item   Type   1A   Size   Small
2. Item 2   Description   This is the second item   Type   1B   Size   Large

```cards-header-actions.jsx
import React from 'react';
import Cards from '@cloudscape-design/components/cards';
import SpaceBetween from '@cloudscape-design/components/space-between';
import ButtonDropdown from '@cloudscape-design/components/button-dropdown';
import Button from '@cloudscape-design/components/button';
import TextFilter from '@cloudscape-design/components/text-filter';
import Header from '@cloudscape-design/components/header';

export default function CardsHeader() {
  const items = [
    {
      name: 'Item 1',
      alt: 'First',
      description: 'This is the first item',
      type: '1A',
      size: 'Small',
    },
    {
      name: 'Item 2',
      alt: 'Second',
      description: 'This is the second item',
      type: '1B',
      size: 'Large',
    },
  ];
  const [selectedItems, setSelectedItems] = React.useState([items[0]]);
  const [filteringText, setFilteringText] = React.useState('');
  return (
    <Cards
      cardDefinition={{
        header: e => e.name,
        sections: [
          {
            id: 'description',
            header: 'Description',
            content: e => e.description,
          },
          {
            id: 'type',
            header: 'Type',
            content: e => e.type,
          },
          {
            id: 'size',
            header: 'Size',
            content: e => e.size,
          },
        ],
      }}
      cardsPerRow={[{ cards: 1 }, { minWidth: 500, cards: 2 }]}
      items={items}
      selectedItems={selectedItems}
      onSelectionChange={({ detail }) => setSelectedItems(detail.selectedItems)}
      trackBy="name"
      ariaLabels={{
        itemSelectionLabel: (e, t) => `select ${t.name}`,
        selectionGroupLabel: 'Item selection',
      }}
      selectionType="multi"
      filter={
        <TextFilter
          filteringText={filteringText}
          filteringPlaceholder="Find resources"
          onChange={({ detail }) => setFilteringText(detail.filteringText)}
        />
      }
      header={
        <Header
          counter={selectedItems.length ? '(' + selectedItems.length + '/2)' : '(2)'}
          actions={
            <SpaceBetween direction="horizontal" size="xs">
              <ButtonDropdown
                disabled={selectedItems.length === 0}
                items={[
                  {
                    id: 'deactivate',
                    text: 'Deactivate',
                  },
                ]}
              >
                Actions
              </ButtonDropdown>
              <Button disabled={selectedItems.length === 0}>Create duplicate</Button>
              <Button variant="primary">Create resource</Button>
            </SpaceBetween>
          }
        >
          Cards title
        </Header>
      }
    />
  );
}
```

### Table header with actions

## Table title (1/2)

Actions
Create duplicate Create resource 

| Variable name | Text value | Type | Description |
| --- | --- | --- | --- |
|  | Item 1 | First | 1A | This is the first item |
|  | Item 2 | Second | 1B | This is the second item |
```table-header-actions.jsx
import React from 'react';
import Table from '@cloudscape-design/components/table';
import SpaceBetween from '@cloudscape-design/components/space-between';
import ButtonDropdown from '@cloudscape-design/components/button-dropdown';
import Button from '@cloudscape-design/components/button';
import TextFilter from '@cloudscape-design/components/text-filter';
import Header from '@cloudscape-design/components/header';

export default function TableHeader() {
  const items = [
    {
      name: 'Item 1',
      alt: 'First',
      description: 'This is the first item',
      type: '1A',
      size: 'Small',
    },
    {
      name: 'Item 2',
      alt: 'Second',
      description: 'This is the second item',
      type: '1B',
      size: 'Large',
    },
  ];
  const [selectedItems, setSelectedItems] = React.useState([items[0]]);
  const [filteringText, setFilteringText] = React.useState('');
  return (
    <Table
      columnDefinitions={[
        { id: 'variable', header: 'Variable name', cell: e => e.name, sortingField: 'name', isRowHeader: true },
        { id: 'value', header: 'Text value', cell: e => e.alt, sortingField: 'alt' },
        { id: 'type', header: 'Type', cell: e => e.type },
        { id: 'description', header: 'Description', cell: e => e.description },
      ]}
      items={items}
      selectedItems={selectedItems}
      onSelectionChange={({ detail }) => setSelectedItems(detail.selectedItems)}
      trackBy="name"
      ariaLabels={{
        itemSelectionLabel: (e, t) => `select ${t.name}`,
        selectionGroupLabel: 'Item selection',
      }}
      selectionType="multi"
      filter={
        <TextFilter
          filteringText={filteringText}
          filteringPlaceholder="Find resources"
          onChange={({ detail }) => setFilteringText(detail.filteringText)}
        />
      }
      header={
        <Header
          counter={selectedItems.length ? '(' + selectedItems.length + '/2)' : '(2)'}
          actions={
            <SpaceBetween direction="horizontal" size="xs">
              <ButtonDropdown
                disabled={selectedItems.length === 0}
                items={[
                  {
                    id: 'deactivate',
                    text: 'Deactivate',
                  },
                ]}
              >
                Actions
              </ButtonDropdown>
              <Button disabled={selectedItems.length === 0}>Create duplicate</Button>
              <Button variant="primary">Create resource</Button>
            </SpaceBetween>
          }
        >
          Table title
        </Header>
      }
    />
  );
}
```

**Global action locations**

Place global actions in the action stripe of the [header](/components/header/index.html.md) component at the top of the page, or as part of the [table](/components/table/index.html.md) or [cards](/components/cards/index.html.md) header. Add actions as [buttons](/components/button/index.html.md) or [button dropdowns](/components/button-dropdown/index.html.md) if users can perform actions on the underlying content.

**Order of actions**

The order of buttons is important when action is required on a data set. It follows the order of major resource management actions.

- Place buttons in this order: *View details, Edit, Delete, Create \[resource name\]*  

  - When the primary action isn't a create action, place it last. For example:* Edit, Delete, Publish \[resource name\]*
- Add other action buttons between the *Edit*   and *Delete*   buttons.
- Add other *Create*   buttons between the primary *Create*   button and the *Delete*   button.
- Place status actions at the far left in the action stripe.  

  - For example: *Deactivate, Activate, Status 3, View details, Edit, Delete, Create \[resource name\]*

**Number of actions**

- For less than five actions, use individual buttons.
- For more than five actions, use a button dropdown to collapse non-primary actions.
- For large action sets or where expandable groups in button dropdowns makes it hard for users to scan the full list, enable filtering.

On mobile viewports with more than one non-primary action, consider moving these actions into a button dropdown to conserve space. Follow the guidelines for [responsive design](/foundation/core-principles/responsive-design/index.html.md).

**Sticky header - ** **optional**

If users need to take an action on resources upon selection, consider using a sticky header in your table or card collection to house your global actions.

**Disabled reasons in button dropdown - ** **optional**

For extra clarity, provide a tooltip with inactive actions that explains why the action is unavailable. These tooltip explanations should be as short as possible, with longer descriptions belong outside the dropdown component.

This feature should be used scarcely because it adds additional information to the interface. Use the tooltip only if the reason an action is inactive is unclear, and there are no other suitable approaches to guide users.

## General guidelines

### Do

- Use only one primary button per page. Primary buttons are like [The Highlander](https://en.wikipedia.org/wiki/Highlander_(film))   , there can be only one.
- Actions that do not relate to one resource should be placed in the page header, or as part of the [table](/components/table/index.html.md)   or [cards](/components/cards/index.html.md)   header.  For example: A primary action in the table header to create a new resource.
- Use buttons for actions.
- Use a button dropdown to present 5-15 contextual actions that users can choose from to initiate one action.

## Writing guidelines

### General writing guidelines

- Use sentence case, but continue to capitalize proper nouns and brand names correctly in context.
- Use end punctuation, except in [headers](/components/header/index.html.md)   and [buttons](/components/button/index.html.md)   . Don't use exclamation points.
- Use present-tense verbs and active voice.
- Don't use *please*   , *thank you*   , ellipsis ( *...*   ), ampersand ( *&*   ), *e.g.*   , *i.e.*   , or *etc.*   in writing.
- Avoid directional language.  

  - For example: use *previous*     not *above*     , use *following*     not *below*    .
- Use device-independent language.  

  - For example: use *choose*     or *select*     not *click*    .

### Component-specific guidelines

#### Button

- For labels of button dropdown, indicate the purpose of the actions set.
- Use an action verb.  

  - For example:    

    - *Rerun*
    - *Edit*
    - *Delete*
- Don't use terminal punctuation (period, exclamation point, question mark, colon) in button labels.
- Follow the writing guidelines for [button](/components/button/index.html.md)  .

## Accessibility guidelines

### General accessibility guidelines

- Follow the guidelines on alternative text and Accessible Rich Internet Applications (ARIA) regions for each component.
- Make sure to define ARIA labels aligned with the language context of your application.
- Don't add unnecessary markup for roles and landmarks. Follow the guidelines for each component.
- Provide keyboard functionality to all available content in a logical and predictable order. The flow of information should make sense.

### Component-specific guidelines

#### Alternative text

- Provide alternative text with the ariaLabel property if there is no button text or if you are conveying additional information through means other than text.  

  - For example, buttons without text, buttons with meaningful icons, or buttons conveying additional information with color.

#### Keyboard interaction

- By default, the tab key focuses the component.
- The enter key performs the action.

## Related patterns

### Actions

Ways to invoke actions in the interface.

[View Documentation](/patterns/general/actions/index.html.md)

### In-context actions

Use in-context actions when there are actions tied to a singular element, resource or container.---

[View Documentation](/patterns/general/actions/incontext-actions/index.html.md)

## Search Cloudscape